There are many query languages for JSON, such as JMES Path and JSON Path, but none of the ones I've found interest me, e.g. JSON Path doesn't allow multiselect query (I can't return a list with different type element [car, plane, boat]) and JMES Path is really simpler compare to the JSON Path and allow the multiselect but doesn't allow the access to the parent node like .. or parent(@) or $(for the source).
So I want a language which can do both, if it's possible a query language simple as JMES Path, but if there is only one and it the most difficult one it's okay I will take it !
PS: I work in javascript !
jq is a JSON Query language with some resemblance to JSONPath, but with the full generality of a Turing-complete programming language. jq
subsumes all of JSON, and many of its constructs are JSON-like.
One of the ways in which problems involving "parents" and "children" can be handled in jq is using jq paths, which are nothing other than JSON arrays all of whose elements are either JSON strings (corresponding to key names) or integers (corresponding to indices into an array). Thus if $p
is the path to some sub-component of a JSON document, then the path to its parent would be $p[:-1]
.
In practice, though, many problems involving parents and/or children can more easily be solved without using full paths. Note in particular that to_entries
can be used with both JSON objects and JSON arrays.
Resources
The main website includes a tutorial, manual, and a Wiki, which has a FAQ, Cookbook, a "Language Description", and a guide for JSONPath users.
Here on stackoverflow, there are currently over 2,000 questions that have the jq tag. See also http://rosettacode.org/wiki/Category:Jq