Parse complex JSON response

Please help to parse JSON response. None of methods in similar topics worked out.

My JSON is:

Summary

{
“zones”:{
“transaction_time”:null,
“elements”:[

  ],
  "globalSchedules":{
     "time":null,
     "duringChange":null,
     "elements":[

     ]
  },
  "controllerParameters":{

  }

},
“tiles”:[
{
“id”:2006,
“parentId”:4630,
“type”:40,
“menuId”:2006,
“orderId”:null,
“visibility”:true,
“params”:{
“description”:“Text information”,
“statusId”:587,
“headerId”:814,
“iconId”:3,
“options”:[

        ]
     }
  },
  {
     "id":2040,
     "parentId":0,
     "type":50,
     "menuId":0,
     "orderId":null,
     "visibility":true,
     "params":{
        "description":"Controller software version",
        "version":"1.1.11",
        "txtId":0,
        "iconId":0,
        "companyId":6,
        "controllerName":"i-3",
        "mainControllerId":0
     }
  },
  {
     "id":2050,
     "parentId":4631,
     "type":1,
     "menuId":0,
     "orderId":null,
     "visibility":true,
     "params":{
        "description":"Temperature sensor",
        "workingStatus":true,
        "txtId":192,
        "value":277,
        "batteryLevel":null,
        "signalStrength":null
     }
  },
  {
     "id":2051,
     "parentId":4631,
     "type":1,
     "menuId":0,
     "orderId":null,
     "visibility":true,
     "params":{
        "description":"Temperature sensor",
        "workingStatus":true,
        "txtId":194,
        "value":286,
        "batteryLevel":null,
        "signalStrength":null
     }
  },
  {
     "id":2052,
     "parentId":4631,
     "type":1,
     "menuId":0,
     "orderId":null,
     "visibility":true,
     "params":{
        "description":"Temperature sensor",
        "workingStatus":true,
        "txtId":795,
        "value":147,
        "batteryLevel":null,
        "signalStrength":null
     }
  },
  {
     "id":2053,
     "parentId":4631,
     "type":1,
     "menuId":0,
     "orderId":null,
     "visibility":true,
     "params":{
        "description":"Temperature sensor",
        "workingStatus":true,
        "txtId":1040,
        "value":304,
        "batteryLevel":null,
        "signalStrength":null
     }
  },
  {
     "id":2054,
     "parentId":4631,
     "type":1,
     "menuId":0,
     "orderId":null,
     "visibility":true,
     "params":{
        "description":"Temperature sensor",
        "workingStatus":false,
        "txtId":196,
        "value":-2030,
        "batteryLevel":null,
        "signalStrength":null
     }
  },
  {
     "id":2055,
     "parentId":4631,
     "type":1,
     "menuId":0,
     "orderId":null,
     "visibility":true,
     "params":{
        "description":"Temperature sensor",
        "workingStatus":false,
        "txtId":197,
        "value":-2030,
        "batteryLevel":null,
        "signalStrength":null
     }
  },
  {
     "id":2056,
     "parentId":4631,
     "type":1,
     "menuId":0,
     "orderId":null,
     "visibility":true,
     "params":{
        "description":"Temperature sensor",
        "workingStatus":false,
        "txtId":1288,
        "value":-2030,
        "batteryLevel":null,
        "signalStrength":null
     }
  },
  {
     "id":2057,
     "parentId":4631,
     "type":1,
     "menuId":0,
     "orderId":null,
     "visibility":true,
     "params":{
        "description":"Temperature sensor",
        "workingStatus":true,
        "txtId":1289,
        "value":236,
        "batteryLevel":null,
        "signalStrength":null
     }
  },
  {
     "id":2058,
     "parentId":4631,
     "type":1,
     "menuId":0,
     "orderId":null,
     "visibility":true,
     "params":{
        "description":"Temperature sensor",
        "workingStatus":true,
        "txtId":221,
        "value":181,
        "batteryLevel":null,
        "signalStrength":null
     }
  },
  {
     "id":2059,
     "parentId":4631,
     "type":1,
     "menuId":0,
     "orderId":null,
     "visibility":true,
     "params":{
        "description":"Temperature sensor",
        "workingStatus":true,
        "txtId":222,
        "value":242,
        "batteryLevel":null,
        "signalStrength":null
     }
  },
  {
     "id":2060,
     "parentId":4631,
     "type":1,
     "menuId":0,
     "orderId":null,
     "visibility":true,
     "params":{
        "description":"Temperature sensor",
        "workingStatus":true,
        "txtId":1308,
        "value":239,
        "batteryLevel":null,
        "signalStrength":null
     }
  },
  {
     "id":4057,
     "parentId":4630,
     "type":6,
     "menuId":3203,
     "orderId":null,
     "visibility":true,
     "params":{
        "description":"Universal status with widgets",
        "statusId":0,
        "iconId":17,
        "widget1":{
           "txtId":573,
           "value":50,
           "unit":6,
           "type":1,
           "params":[
              0,
              0,
              0,
              0,
              0
           ]
        },
        "widget2":{
           "txtId":0,
           "value":28,
           "unit":6,
           "type":1,
           "params":[
              0,
              0,
              0,
              0,
              0
           ]
        }
     }
  },
  {
     "id":4063,
     "parentId":4630,
     "type":23,
     "menuId":2320,
     "orderId":null,
     "visibility":true,
     "params":{
        "description":"Built-in valve",
        "workingStatus":true,
        "valveNumber":1,
        "currentTemp":182,
        "returnTemp":303,
        "setTempCorrection":0,
        "openingPercentage":0,
        "valvePump":0,
        "boilerProtection":1,
        "returnProtection":0,
        "setTemp":10,
        "txtId":992
     }
  },
  {
     "id":4064,
     "parentId":4630,
     "type":23,
     "menuId":2420,
     "orderId":null,
     "visibility":true,
     "params":{
        "description":"Built-in valve",
        "workingStatus":true,
        "valveNumber":2,
        "currentTemp":241,
        "returnTemp":303,
        "setTempCorrection":0,
        "openingPercentage":100,
        "valvePump":0,
        "boilerProtection":0,
        "returnProtection":0,
        "setTemp":34,
        "txtId":993
     }
  },
  {
     "id":4066,
     "parentId":4630,
     "type":23,
     "menuId":2520,
     "orderId":null,
     "visibility":true,
     "params":{
        "description":"Built-in valve",
        "workingStatus":true,
        "valveNumber":3,
        "currentTemp":239,
        "returnTemp":303,
        "setTempCorrection":0,
        "openingPercentage":100,
        "valvePump":0,
        "boilerProtection":0,
        "returnProtection":0,
        "setTemp":53,
        "txtId":3449
     }
  },
  {
     "id":4600,
     "parentId":4633,
     "type":6,
     "menuId":0,
     "orderId":null,
     "visibility":true,
     "params":{
        "description":"Universal status with widgets",
        "statusId":0,
        "iconId":167,
        "widget1":{
           "txtId":730,
           "value":0,
           "unit":-1,
           "type":0,
           "params":[
              0,
              0,
              0,
              0,
              0
           ]
        },
        "widget2":{
           "txtId":3731,
           "value":0,
           "unit":-1,
           "type":0,
           "params":[
              0,
              0,
              0,
              0,
              0
           ]
        }
     }
  },
  {
     "id":4605,
     "parentId":4633,
     "type":6,
     "menuId":0,
     "orderId":null,
     "visibility":true,
     "params":{
        "description":"Universal status with widgets",
        "statusId":0,
        "iconId":167,
        "widget1":{
           "txtId":4023,
           "value":0,
           "unit":-1,
           "type":0,
           "params":[
              0,
              0,
              0,
              0,
              0
           ]
        },
        "widget2":{
           "txtId":3028,
           "value":0,
           "unit":-1,
           "type":0,
           "params":[
              0,
              0,
              0,
              0,
              0
           ]
        }
     }
  },
  {
     "id":4610,
     "parentId":4632,
     "type":11,
     "menuId":0,
     "orderId":null,
     "visibility":true,
     "params":{
        "description":"Relay",
        "workingStatus":true,
        "txtId":645,
        "iconId":98
     }
  },
  {
     "id":4611,
     "parentId":4632,
     "type":11,
     "menuId":0,
     "orderId":null,
     "visibility":true,
     "params":{
        "description":"Relay",
        "workingStatus":true,
        "txtId":646,
        "iconId":98
     }
  },
  {
     "id":4612,
     "parentId":4632,
     "type":11,
     "menuId":0,
     "orderId":null,
     "visibility":true,
     "params":{
        "description":"Relay",
        "workingStatus":true,
        "txtId":1333,
        "iconId":98
     }
  },
  {
     "id":4613,
     "parentId":4632,
     "type":6,
     "menuId":4614,
     "orderId":null,
     "visibility":true,
     "params":{
        "description":"Universal status with widgets",
        "statusId":0,
        "iconId":98,
        "widget1":{
           "txtId":1177,
           "value":0,
           "unit":7,
           "type":1,
           "params":[
              0,
              0,
              0,
              0,
              0
           ]
        },
        "widget2":{
           "txtId":0,
           "value":0,
           "unit":7,
           "type":1,
           "params":[
              0,
              0,
              0,
              0,
              0
           ]
        }
     }
  },
  {
     "id":4630,
     "parentId":0,
     "type":60,
     "menuId":0,
     "orderId":1,
     "visibility":true,
     "expanded":true,
     "params":{
        "description":"Container",
        "txtId":1290,
        "iconId":138
     }
  },
  {
     "id":4631,
     "parentId":0,
     "type":60,
     "menuId":0,
     "orderId":2,
     "visibility":true,
     "expanded":true,
     "params":{
        "description":"Container",
        "txtId":1617,
        "iconId":87
     }
  },
  {
     "id":4632,
     "parentId":0,
     "type":60,
     "menuId":0,
     "orderId":3,
     "visibility":true,
     "expanded":false,
     "params":{
        "description":"Container",
        "txtId":642,
        "iconId":98
     }
  },
  {
     "id":4633,
     "parentId":0,
     "type":60,
     "menuId":0,
     "orderId":4,
     "visibility":true,
     "expanded":false,
     "params":{
        "description":"Container",
        "txtId":729,
        "iconId":167
     }
  },
  {
     "id":4660,
     "parentId":4630,
     "type":6,
     "menuId":0,
     "orderId":null,
     "visibility":true,
     "params":{
        "description":"Universal status with widgets",
        "statusId":0,
        "iconId":17,
        "widget1":{
           "txtId":2442,
           "value":23,
           "unit":6,
           "type":1,
           "params":[
              0,
              0,
              0,
              0,
              0
           ]
        },
        "widget2":{
           "txtId":0,
           "value":30,
           "unit":6,
           "type":1,
           "params":[
              0,
              0,
              0,
              0,
              0
           ]
        }
     }
  }

]
}

I need to pull sensor values under
“tiles”, selected “id” and under nested “params” there is “SetTemp” and “Value” figures.
Please advise how to do it.

Something like

value_template: '{{ value_json["tiles"][0]["params"]["value"] }}'

doesn’t work.

Any help on pulling, for instance, “value” data from Temperature sensor with ID = 2059 will be pretty much appreciated.
Thank you!

Current try I have in configuration.yaml:

    name: JSONtech
    resource: "----my resource-----"
    headers:
      Authorization: !secret my_bearer
    value_template: '{{ value_json["tiles"][2]["params"]["value"] }}'

results in empty sensor…

because it’s not valid json.

You have a comma after the last item in pretty much every list/dictionary. That’s against json validation.

Also, next time, format it properly following the forum guidelines.

This is what we see with your bad formatting:
image

This is what proper formatting looks like:
image

The format is correct, like you metioned, it can’t be pasted in text with JSON formatting.

Any ideas on how to pull necessary data?

The format is not correct. You have trailing comma’s on your collection. It fails validation.

And just to be more clear, These are collections:

dictionary

"Foo": {
    "A":"A",
    "B":"B",
    "C":"C"
}

list

"Foo": [
    "A",
    "B",
    "C"
]

Notice how "C":"C" and "C" don’t have a comma after them? All your collections have a comma there. That’s not valid and will cause the sensor to fail because it cannot properly parse the json.

@petro

Here I pasted the data and it said it was valid


Here is mu JSON file:
https://fex.net/ru/s/flr3sac

Did you read what it says? That formatter fixes your issues. Paste your value into a validator that doesn’t fix the issues.

This validator doesn’t fix your issues and tells you wants wrong:

@petro
Where do you see a trailing comma in my source file?
Open my file please.

Sorry, I’m not going to download any files that I don’t trust. I’m taking it from your original post which contains the commas, which you already edited out apparently.

What platform are you using to get the information?

Actually, no your selector is not correct. What value are you trying to get?

value_template: '{{ value_json["tiles"][0]["params"]["description"] }}'
value_template: '{{ value_json["tiles"][0]["params"]["version"] }}'
value_template: '{{ value_json["tiles"][0]["params"]["txtId"] }}'
etc...

but each object is not the same, so the only one that will work for all indexes will be description.

EDIT: But it seems that your second index actually has ‘value’… so that should work. So back to my other question. What platform?

Yes, I tried to edit the initial post with formatting, but still it looks ugly.
Source looks like this:

I am using rest platform.
Tried your suggestion:

value_template: '{{ value_json["tiles"][0]["params"]["description"] }}'

Now it says “Unknown” in my JSONtech sensor
image

@petro
Sorry, I changed to second index and it worked out!
THANK YOU a lot!

Could you please tell me if these values are fetched periodically (as I refresh HA page or Android App)?
I mean - if values are changed in the source, will they be dynamically changed in my Sensor?

Yes they should, and i believe the default scan_interval is 30 seconds. As long as the index order doesn’t change, it should work.