Using the jsonpath-plus module (typescript), I'm attempting to navigate to a specific object in a json document. The target object is several levels down, and includes passing through 2 levels of arrays. The following jsonpath statement:
$..['gmd:DQ_AbsoluteExternalPositionalAccuracy']
returns the following result in the online jsonpath test website jsonpath.com:
[
{
"gmd:nameOfMeasure": {
"gco:CharacterString": "Difference to ICESat LE90"
},
"gmd:result": {
"gmd:DQ_QuantitativeResult": {
"gmd:valueUnit": {
"@xlink:href": "http://www.opengis.net/def/uom/OGC/1.0/metre"
},
"gmd:value": {
"gco:Record": {
"gco:Real": "0.655608"
}
}
}
}
},
{
"gmd:nameOfMeasure": {
"gco:CharacterString": "Difference to ICESat Vertical Mean"
},
"gmd:result": {
"gmd:DQ_QuantitativeResult": {
"gmd:valueUnit": {
"@xlink:href": "http://www.opengis.net/def/uom/OGC/1.0/metre"
},
"gmd:value": {
"gco:Record": {
"gco:Real": "-0.005536"
}
}
}
}
},
{
"gmd:nameOfMeasure": {
"gco:CharacterString": "Difference to ICESat Vertical RMSE"
},
"gmd:result": {
"gmd:DQ_QuantitativeResult": {
"gmd:valueUnit": {
"@xlink:href": "http://www.opengis.net/def/uom/OGC/1.0/metre"
},
"gmd:value": {
"gco:Record": {
"gco:Real": "0.398874"
}
}
}
}
},
{
"gmd:nameOfMeasure": {
"gco:CharacterString": "Difference to GCP LE90"
},
"gmd:result": {
"gmd:DQ_QuantitativeResult": {
"gmd:valueUnit": {
"@xlink:href": "http://www.opengis.net/def/uom/OGC/1.0/metre"
},
"gmd:value": {
"gco:Record": {
"gco:Real": "2.897789"
}
}
}
}
},
{
"gmd:nameOfMeasure": {
"gco:CharacterString": "Difference to GCP Vertical Mean"
},
"gmd:result": {
"gmd:DQ_QuantitativeResult": {
"gmd:valueUnit": {
"@xlink:href": "http://www.opengis.net/def/uom/OGC/1.0/metre"
},
"gmd:value": {
"gco:Record": {
"gco:Real": "-0.383740"
}
}
}
}
},
{
"gmd:nameOfMeasure": {
"gco:CharacterString": "Difference to GCP Vertical RMSE"
},
"gmd:result": {
"gmd:DQ_QuantitativeResult": {
"gmd:valueUnit": {
"@xlink:href": "http://www.opengis.net/def/uom/OGC/1.0/metre"
},
"gmd:value": {
"gco:Record": {
"gco:Real": "1.760134"
}
}
}
}
},
{
"gmd:nameOfMeasure": {
"gco:CharacterString": "Absolute horizontal accuracy CE90"
},
"gmd:result": {
"gmd:DQ_QuantitativeResult": {
"gmd:valueUnit": {
"@xlink:href": "http://www.opengis.net/def/uom/OGC/1.0/metre"
},
"gmd:value": {
"gco:Record": {
"gco:Real": "10"
}
}
}
}
},
{
"gmd:nameOfMeasure": {
"gco:CharacterString": "Absolute vertical accuracy LE90"
},
"gmd:result": {
"gmd:DQ_QuantitativeResult": {
"gmd:valueUnit": {
"@xlink:href": "http://www.opengis.net/def/uom/OGC/1.0/metre"
},
"gmd:value": {
"gco:Record": {
"gco:Real": "10"
}
}
}
}
}
]
The object I need to retrieve in this example is the last object (containing the string "Absolute vertical accuracy LE90"), but I can't count on it always being in the same position. I've tried to filter this result set by appending
[?(@['gmd:nameOfMeasure']['gco:CharacterString']=="Absolute vertical accuracy LE90")]
to the original jsonpath expression (resulting in the new expression
$..['gmd:DQ_AbsoluteExternalPositionalAccuracy'][?(@['gmd:nameOfMeasure']['gco:CharacterString']=="Absolute vertical accuracy LE90")]
but the filter statement has no effect on the result. Just for kicks, I tried the same expression in the Jayway jsonpath implementation for java at https://jsonpath.herokuapp.com/ and successfully filtered the result down to the one desired object.
Can anyone tell me how to filter this result set properly using jsonpath-plus?
Query your sample JSON using
works for me; maybe you could simply query in two steps.
Since only the inner JSON was provided I can only guestimate what's wrong when querying the full JSON. One thing to look out for: JsonPath-Plus expects that the JSON is wrapped in square brackets: