I'm consuming a JSON feed that returns a structure with an array of irregular objects - I can't predict what's in the array, and whatever is there will change over time. A simple example is
{
"content":
[
{
"person" : "john"
},
{
"car" : "Audi"
}
]
}
The JsonPath query
$.content.[0]
returns the first object in that array. But, I need a jsonpath query that returns the literal NAME of the first property of that object, in this case I need the query to return "person". Is this possible?
A JsonPath expression begins with the dollar sign ( $ ) character, which refers to the root element of a query. The dollar sign is followed by a sequence of child elements, which are separated via dot (code) notation or via the square brackets (code).
JSONPath is a query language for JSON, similar to XPath for XML. It allows you to select and extract data from a JSON document. You use a JSONPath expression to traverse the path to an element in the JSON structure.
JsonPath is an alternative to using XPath for easily getting values from a Object document. It follows the Groovy dot notation syntax when getting an object from the document. You can regard it as an alternative to XPath for XML.
JPath is a language for querying and manipulating JSON elements. You can use JPath to compute values, such as strings, numbers, and boolean values, from JSON elements. Basic selection. Select elements by using a forward slash (/). Select array items by using square brackets ( [ ] ).
$.content.[0].*~
Tested on JSON path
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With