JSONPath explained
JSONPath |
Paradigm: | Query language |
Year: | 2007 (blogged) 2024 (standardized) |
Designer: | Stefan Gössner |
Developer: | Stefan Gössner |
Influenced By: | XPath |
JSONPath |
Status: | Proposed Standard |
Organization: | IETF |
Editors: | Stefan Gössner Glyn Normington Carsten Bormann |
Authors: | Stefan Gössner |
Base Standards: | JSON |
Related Standards: | XPath |
In computer software, JSONPath is a query language for querying values in JSON. The uses of JSONPath include:
- Selecting a specific node in a JSON value
- Retrieving a set of nodes from a JSON value, based on specific criteria
- Navigating through complex JSON values to retrieve the required data.
JSONPath queries are path expressions written as strings, e.g. $.foo
.
Example
The JSONPath expression $.store.book[0]
applied to the following JSON value:selects the first book (by Nigel Rees):
The expression $.store.book[*].price
extracts the prices of books: 8.95 and 22.99 (since [*]
selects all the nodes of an array).
The expression $..price
extracts all the prices: 8.95, 22.99, and 399.
History
JSONPath was first described in an online article.[1] by Stefan Gössner in February 2007. Gössner also published initial implementations in JavaScript and PHP.
Subsequently, over fifty implementations were created in various programming languages. The JSONPath Comparison Project lists many of these implementations and compares their behavior.[2] JSONPath is widely used in the Java ecosystem.[3]
In 2024, the IETF published a standard for JSONPath as .[4]
Research
- Scalable Processing of Contemporary Semi-Structured Data on Commodity Parallel Processors - A Compilation-based Approach[5] describes an optimisation which converts JSONPath queries into parallel programs with bounded memory requirements.
- Supporting Descendants in SIMD-Accelerated JSONPath[6] describes an optimisation of JSONPath descendant queries when streaming potentially very large JSON values.
- τJSONPath: A Temporal Extension of the JSONPath Language for the τJSchema Framework[7] describes a temporal extension of JSONPath that supports querying the versions of a JSON value over its version history.
Alternatives
- JMESPath[8] is a query language for JSON with features that go far beyond JSONPath. It has a specification, a compliance test suite, and multiple implementations in various languages.
- JSONata[9] An open source query and transformation language for JSON data inspired by XPath 3.1.
- JSON Pointer[10] defines a string syntax for identifying a single value within a given JSON value of known structure.
- JSONiq[11] is a query and transformation language for JSON.
- XPath 3.1[12] is an expression language that allows the processing of values conforming to the XDM[13] data model. The version 3.1 of XPath supports JSON as well as XML.
- is like for JSON data - you can use it to slice and filter and map and transform structured data.
Notes and References
- Web site: Gössner . Stefan . JSONPath - XPath for JSON . 22 March 2024 . https://web.archive.org/web/20070911145032/https://goessner.net/articles/JsonPath/ . 11 September 2007.
- Web site: Burgmer . Christoph . JSONPath Comparison . 22 March 2024 . https://web.archive.org/web/20240303064503/https://cburgmer.github.io/json-path-comparison/ . 3 March 2024.
- Book: Friesen . Jeff . Java XML and JSON: Document Processing for Java SE . Extracting JSON values with JsonPath . 11 January 2019 . Apress . 978-1484243299 . 2nd.
- Gössner . Stefan . Normington . Glyn . Bormann . Carsten . RFC 9535 JSONPath: Query Expressions for JSON . The RFC Series . February 2024 . The Internet Engineering Task Force (IETF) . 22 March 2024.
- Book: Jiang . Lin . Sun . Xiaofan . Farooq . Umar . Zhao . Zhijia . Scalable Processing of Contemporary Semi-Structured Data on Commodity Parallel Processors - A Compilation-based Approach . Proceedings of the Twenty-Fourth International Conference on Architectural Support for Programming Languages and Operating Systems . April 2019 . 79–92 . 10.1145/3297858.3304008. 978-1-4503-6240-5 .
- Gienieczko . Mateusz . Murlak . Filip . Paperman . Charles . Supporting Descendants in SIMD-Accelerated JSONPath . Conference on Architectural Support for Programming Languages and Operating Systems . February 2024 . 4.
- Book: Brahmia . Zouhaier . Grandi . Fabio . Brahmia . Safa . Bouaziz . Rafik . τJSONPath: A Temporal Extension of the JSONPath Language for the τJSchema Framework . Lecture Notes in Networks and Systems . Artificial Intelligence and Smart Environment . 2023 . 635. 844–853 . 10.1007/978-3-031-26254-8_123 . 978-3-031-26253-1 .
- Web site: Saryerwinnie . James . JMESPath . 23 March 2024 . https://web.archive.org/web/20240314161344/https://jmespath.org/ . 14 March 2024.
- Web site: Bailey . Matt . JSONata . 25 March 2024 . https://archive.today/20240325153137/https://jsonata.org/ . 25 March 2024.
- Bryan . Paul . Zyp . Kris . Nottingham . Mark . RFC 6901 JavaScript Object Notation (JSON) Pointer . The RFC Series . April 2013 . The Internet Engineering Task Force (IETF) . 23 March 2024.
- Web site: JSONiq . https://web.archive.org/web/20240113022357/https://www.jsoniq.org/ . 13 January 2024 . 23 March 2024.
- Web site: Robie . Jonathan . Dyck . Michael . Spiegel . Josh . w3c.org . XML Path Language (XPath) 3.1 . 24 March 2024 . https://web.archive.org/web/20240118065535/https://www.w3.org/TR/xpath-31/ . 18 January 2024.
- Web site: XQuery and XPath Data Model . w3c.org . Norman . Tovey-Walsh . John . Snelson . Andrew . Coleman . 24 March 2024 . https://web.archive.org/web/20240118065618/https://www.w3.org/TR/xpath-datamodel-31/ . 18 January 2024.