using jsonpath (https://www.npmjs.com/package/jsonpath) to query an array of objects. I would like to return specific keyed objects from a nested array.
Data:
[
{
"payload": {
"data": {
"battery": {
"name": "Battery",
"value": 45.95860848091411,
"units": "%",
"precision": 0
},
"humidity": {
"name": "Humidity",
"value": 27.84230269716663,
"units": "%",
"precision": 2
},
"temperature": {
"name": "Temperature",
"value": 4.3758105786304675,
"units": "°",
"precision": 2
}
},
"timeStamp": 1657356781,
"deviceId": "172849"
},
"timeStamp": "2022-07-09T07:53:00.000Z"
},
{
"payload": {
"data": {
"battery": {
"name": "Battery",
"value": 15.088388240727735,
"units": "%",
"precision": 0
},
"humidity": {
"name": "Humidity",
"value": 55.695616989217875,
"units": "%",
"precision": 2
},
"temperature": {
"name": "Temperature",
"value": 22.08980374920423,
"units": "°",
"precision": 2
}
},
"timeStamp": 1657356840,
"deviceId": "172849"
},
"timeStamp": "2022-07-09T07:55:59.000Z"
}
]
Desired Result with temperature and humidity only:
[
{
"humidity": {
"name": "Humidity",
"value": 27.84230269716663,
"units": "%",
"precision": 2
},
"temperature": {
"name": "Temperature",
"value": 4.3758105786304675,
"units": "°",
"precision": 2
}
},
{
"humidity": {
"name": "Humidity",
"value": 55.695616989217875,
"units": "%",
"precision": 2
},
"temperature": {
"name": "Temperature",
"value": 22.08980374920423,
"units": "°",
"precision": 2
}
}
]
I tried this and some other variations to no avail:
jp.query(data, "$..payload.data['humidity']['temperature']");
I can do it with 2 queries, but would like to get it all in one go. thank you for looking.