I’m performing a GET request to get data from the new Google Nest APIs. I’m successfully getting back my data, but I can’t figure out how to extract the data I need to read.
The API returns a JSON blob that looks like this (parts removed for brevity):
{
"name": "removed for privacy",
"type": "sdm.devices.types.THERMOSTAT",
...
"traits": {
"sdm.devices.traits.Humidity": {
"ambientHumidityPercent": 56
},
...
"sdm.devices.traits.ThermostatMode": {
"mode": "COOL",
"availableModes": [
"HEAT",
"COOL",
"HEATCOOL",
"OFF"
]
},
}
I’m trying to read the thermostat mode, which is located at response['traits']['sdm.devices.traits.ThermostatMode']['mode'
].
The dots in the one variable name are causing me problems.
I can read things like name with the expression $response.name
.
To drill into the parameter I need, I tried $response.traits.sdm.devices.traits.ThermostatMode.mode
which did not return anything. I also could not get $response.traits.sdm.devices.traits.ThermostatMode
.
I can read $response.traits
, which gives me this:
[sdm.devices.traits.Info:[customName:], sdm.devices.traits.Humidity:[ambientHumidityPercent:65], sdm.devices.traits.Connectivity:[status:ONLINE], sdm.devices.traits.Fan:[timerMode:OFF], sdm.devices.traits.ThermostatMode:[mode:COOL, availableModes:[HEAT, COOL, HEATCOOL, OFF]], sdm.devices.traits.ThermostatEco:[availableModes:[OFF, MANUAL_ECO], mode:OFF, heatCelsius:18.92499, coolCelsius:24.59267], sdm.devices.traits.ThermostatHvac:[status:OFF], sdm.devices.traits.Settings:[temperatureScale:FAHRENHEIT], sdm.devices.traits.ThermostatTemperatureSetpoint:[coolCelsius:23.66678], sdm.devices.traits.Temperature:[ambientTemperatureCelsius:23.65999]]
I suppose I could get to the value I need with string parsing, but that feels fragile.
Any suggestions?