Open JSON File

Information, tips and instructions

JSON Queries and Transformations

JSONPath and JMESPath are both query languages for JSON files. They are to some extent similar to XPath query language for XML. Below we will review both of them so you can decide which one is better for you.

JMESPath

JMESPath is JSON query language written by James Saryerwinnie. It is a feature rich query language which supports following features:

  • List projections. Creates an array based on a list projection of queried JSON elements.
  • Slice projections. Creates an array based on a slice projection from an array of queried JSON elements.
  • Object projections. Creates an array based from on a projection of queried JSON elements from an object.
  • Flatten projections. Flattens nested structures into a flat array.
  • Filter projections. Filters element in projections based on the filter expression.
  • Multiselect queries. Selects multiple elements in a projection. Result is produced as a nested array.
  • Predefined functions. Allows to use functions on queried elements. Full list of functions is defined in JMESPath spec.

Full specification of JMESPath is available at http://jmespath.org/.

JSONPath

JSONPath is a port of XPath for XML to JSON by Stefan Gössner. JSONPath is ported to other programming languages and multiple implementations of JSONPath are available including JSONPath for Javascript, JSONPath for Java.

JSONPath contains similar operations to XPath which include:

  • Access and query elements of JSON using a “path” notation
  • Get all child elements of a certain JSON element
  • Get specific (by index) child elements of a certain JSON element
  • Get JSON elements filtered by JSONPath expression

Full specification of JSONPath is available at https://goessner.net/articles/JsonPath/.

JSON Transformation

Besides querying JSON it is possible to transform the JSON document using JSON transformation libraries. JSON transformation libraries like JOLT can perform different transformations on JSON including shift, default, sort, remove, cardinality. JOLT can also include custom code to perform certain calculations based on JSON data and output it into resulting JSON. JOLT language is quite complex and is outside of the scope of this website. For more information of it refer to JOLT Manual.