JSON scraping (multiscrape?)

Edited as per first response… does this make it easier?

Consider the following JSON (made up and simplified version of actual responses)

{
  "numItems": 2,
  "items": [
     {
      "name":"Item 1",
      "notWanted": true,
      "Interesting Data 1":"Interesting Text",
      "Interesting Data 2":"More Interesting Text",
      "UnInteresting Data":"Not So Interesting Text"
     },
     {
      "name":"Item 2",
      "Interesting Data 1":"Interesting Text",
      "Interesting Data 2":"More Interesting Text",
      "UnInteresting Data":"Not So Interesting Text"
     }
   ]
}

Using multiscrape (or REST as suggested below), I want to extract to a single sensor the number of items (easy), but then add a single attribute that lists Items but ONLY where the item does not contain the key ‘NotWanted’.

From the example above, I would therefore only want Item 2 as it does not contain the key NotWanted.

I also only want to capture the key values for some of the keys. See ‘Interesting Data x’ in example…

I’m at a loss as to where to start to only extract the items that don’t contain a specific key or how to only extract the key:value pairs I want.

Thanks for any pointers

Don’t use scrape with JSON, use Rest.

Please post your example JSON as code using the </> button so the quotes aren’t messed up, then we can copy-paste it to work on examples.

Updated original question… thanks

1 Like
{{ value_json['items']|rejectattr('notWanted','defined')|list }}

…will omit Item 1. Explain, ideally with real data, how you’d like the filtered information to be structured.