#Using JSON queries

1 messages · Page 1 of 1 (latest)

marble karma
#

I've been struggling with this. I'm trying to buld a blueprint that needs to consume some data from a service that is returned as JSON. Ideally, I would be able to extract the data I need with a JSON Query (which I've already got) but I can't seem to find a way to use the JSON Query in any of the blueprint templating.

Example data object:

{
  "lock.test_lab": {
    "bc0abfff-0000-0000-0000-000000000000": {
      "name": "mary",
      "code": "3333"
    },
    "83fb848f-0000-0000-0000-000000000000": {
      "name": "test - jane",
      "code": "2222"
    },
    "ecab9511-0000-0000-0000-000000000000": {
      "name": "test - bob",
      "code": "1111"
    }
  }
}

this all gets dumped into a codes variable during the automation run. The lock.test_lab is in a variable lock.

I would love to be able to do some processing on the stuff that would be returned from the following jq

codes[lock] | [.[] | select(.name | contains("test -")) | .name] but anytime I try to a filter like that, or call something like jsonpath_query (which is apparently not part of the available jinja filters we have, then HA just tells me that there was a failure to initialize the blueprint pointing at my call.

So... is there a way to use jq type query paths with blueprints???

keen pebble
#
{{
  codes[lock].items()
    | selectattr('1.name', 'search', 'test')
    | map(attribute='1.name')
    | list
}}
#

Something like that should work

#

It returns this with the data you provided

[
  "test - jane",
  "test - bob"
]
marble karma
#

Thanks! let me give that a try

naive hatch
#

Interesting