I have a JSON string that's being returned by a HTTP Request to an external service. I have a format into which I need this JSON string to be parsed for a library that comes downstream in my flow. I'm not sure where to start on how to manipulate the JSON in node red to remove the elements I don't need, and additionally to move some child elements up to the top.
Any pointers, help, or examples would be very much appreciated.
Input string example:
{
"objectIdFieldName" : "OBJECTID",
"uniqueIdField" :
{
"name" : "OBJECTID",
"isSystemMaintained" : true
},
"globalIdFieldName" : "",
"geometryType" : "esriGeometryPoint",
"spatialReference" : {
"wkid" : 102100,
"latestWkid" : 3857
},
"fields" : [
{
"name" : "StationNum",
"type" : "esriFieldTypeInteger",
"alias" : "StationNum",
"sqlType" : "sqlTypeOther",
"domain" : null,
"defaultValue" : null
},
{
"name" : "Height",
"type" : "esriFieldTypeDouble",
"alias" : "Height",
"sqlType" : "sqlTypeOther",
"domain" : null,
"defaultValue" : null
}
],
"features" : [
{
"attributes" : {
"StationNum" : 558105,
"Height" : 1.11
}
},
{
"attributes" : {
"StationNum" : 558018,
"Height" : 0.92
}
},
{
"attributes" : {
"StationNum": 558019,
"Height": 1.82
}
]
What I actually need is just the part from the 'features' section, but I also need to remove the "attributes": {} element. Ie, bring the StationNum and Height up a level. I've also noticed that the StationName, despite being a number, needs to be wrapped with quotes " ".
The top part of the JSON before "features" can be completely dropped.
Example of what I'm after:
[
{
"StationNum": "558105",
"Height": 1.11
},
{
"tag": "558018",
"value": 0.92
},
{
"tag": "558019",
"value": 1.82
},
]
EDIT:
Looks like a Change node + JSONata might be what I'm after, but am struggling to get it working.