JSONPath
{{Short description|A standard syntax for querying JSON values}}
{{Infobox programming language
| name = JSONPath
| paradigm = Query language
| year = 2007 (blogged)
2024 (standardized)
| designer = Stefan Gössner
| developer = Stefan Gössner
| latest_release_version =
| latest_release_date = {{Start date and age|2024|02}}
| implementations =
| influenced_by = XPath
| influenced =
| website =
}}
{{Infobox technology standard
| title = JSONPath
| long_name =
| image =
| image_size =
| alt =
| caption =
| abbreviation =
| native_name =
| native_name_lang =
| status = Proposed Standard
| year_started = {{Start date|2024|02}}
| first_published =
| version =
| version_date =
| preview =
| preview_date =
| organization = IETF
| committee =
| series =
| editors = Stefan Gössner
Glyn Normington
Carsten Bormann
| authors = Stefan Gössner
| base_standards = JSON
| related_standards = XPath
| predecessor =
| successor =
| domain =
| license =
| copyright =
| website =
}}
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:
{
"store": {
"book": [
{ "author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{ "author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 399
}
}
}
selects the first book (by Nigel Rees):
{
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
}
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{{cite web |last1=Gössner |first1=Stefan |title=JSONPath - XPath for JSON |url=https://goessner.net/articles/JsonPath/ |access-date=22 March 2024 |archive-url=https://web.archive.org/web/20070911145032/https://goessner.net/articles/JsonPath/ |archive-date=11 September 2007}} 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.{{cite web |last1=Burgmer |first1=Christoph |title=JSONPath Comparison |url=https://cburgmer.github.io/json-path-comparison/ |access-date=22 March 2024 |archive-url=https://web.archive.org/web/20240303064503/https://cburgmer.github.io/json-path-comparison/ |archive-date=3 March 2024}} JSONPath is widely used in the Java ecosystem.{{cite book |last1=Friesen |first1=Jeff |title=Java XML and JSON: Document Processing for Java SE |chapter=Extracting JSON values with JsonPath |date=11 January 2019 |publisher=Apress |isbn=978-1484243299 |edition=2nd}}
In 2024, the IETF published a standard for JSONPath as {{IETF RFC|9535|link=no}}.{{cite journal |last1=Gössner |first1=Stefan |last2=Normington |first2=Glyn |last3=Bormann |first3=Carsten |title=RFC 9535 JSONPath: Query Expressions for JSON |url=https://www.rfc-editor.org/rfc/rfc9535 |website=The RFC Series |date=February 2024 |publisher=The Internet Engineering Task Force (IETF) |access-date=22 March 2024}}
Research
- Scalable Processing of Contemporary Semi-Structured Data on Commodity Parallel Processors - A Compilation-based Approach{{cite book |last1=Jiang |first1=Lin |last2=Sun |first2=Xiaofan |last3=Farooq |first3=Umar |last4=Zhao |first4=Zhijia |chapter=Scalable Processing of Contemporary Semi-Structured Data on Commodity Parallel Processors - A Compilation-based Approach |title=Proceedings of the Twenty-Fourth International Conference on Architectural Support for Programming Languages and Operating Systems |date=April 2019 |pages=79–92 |doi=10.1145/3297858.3304008|isbn=978-1-4503-6240-5 }} describes an optimisation which converts JSONPath queries into parallel programs with bounded memory requirements.
- Supporting Descendants in SIMD-Accelerated JSONPath{{cite journal |last1=Gienieczko |first1=Mateusz |last2=Murlak |first2=Filip |last3=Paperman |first3=Charles |title=Supporting Descendants in SIMD-Accelerated JSONPath |journal=Conference on Architectural Support for Programming Languages and Operating Systems |date=February 2024 |volume=4}} 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{{cite book |last1=Brahmia |first1=Zouhaier |last2=Grandi |first2=Fabio |last3=Brahmia |first3=Safa |last4=Bouaziz |first4=Rafik |chapter=τJSONPath: A Temporal Extension of the JSONPath Language for the τJSchema Framework |series=Lecture Notes in Networks and Systems |title=Artificial Intelligence and Smart Environment |date=2023 |volume=635|pages=844–853 |doi=10.1007/978-3-031-26254-8_123 |isbn=978-3-031-26253-1 }} describes a temporal extension of JSONPath that supports querying the versions of a JSON value over its version history.
Alternatives
- JMESPath{{cite web |last1=Saryerwinnie |first1=James |title=JMESPath |url=https://jmespath.org/ |access-date=23 March 2024 |archive-url=https://web.archive.org/web/20240314161344/https://jmespath.org/ |archive-date=14 March 2024}} 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{{cite web |last1=Bailey |first1=Matt |title=JSONata |url=https://jsonata.org/ |access-date=25 March 2024 |archive-url=https://archive.today/20240325153137/https://jsonata.org/ |archive-date=25 March 2024}} An open source query and transformation language for JSON data inspired by XPath 3.1.
- JSON Pointer{{cite journal |last1=Bryan |first1=Paul |last2=Zyp |first2=Kris |last3=Nottingham |first3=Mark |title=RFC 6901 JavaScript Object Notation (JSON) Pointer |url=https://www.rfc-editor.org/rfc/rfc6901 |website=The RFC Series |date=April 2013 |publisher=The Internet Engineering Task Force (IETF) |access-date=23 March 2024}} defines a string syntax for identifying a single value within a given JSON value of known structure.
- JSONiq{{cite web |title=JSONiq |url=https://www.jsoniq.org/ |archive-url=https://web.archive.org/web/20240113022357/https://www.jsoniq.org/ |archive-date=13 January 2024 |access-date=23 March 2024}} is a query and transformation language for JSON.
- XPath 3.1{{cite web |last1=Robie |first1=Jonathan |last2=Dyck |first2=Michael |last3=Spiegel |first3=Josh |website=w3c.org |title=XML Path Language (XPath) 3.1 |url=https://www.w3.org/TR/xpath-31/ |access-date=24 March 2024 |archive-url=https://web.archive.org/web/20240118065535/https://www.w3.org/TR/xpath-31/ |archive-date=18 January 2024}} is an expression language that allows the processing of values conforming to the XDM{{cite web |title=XQuery and XPath Data Model |website=w3c.org |first1=Norman |last1=Tovey-Walsh |first2=John |last2=Snelson |first3=Andrew |last3=Coleman |url=https://www.w3.org/TR/xpath-datamodel-31/ |access-date=24 March 2024 |archive-url=https://web.archive.org/web/20240118065618/https://www.w3.org/TR/xpath-datamodel-31/ |archive-date=18 January 2024}} data model. The version 3.1 of XPath supports JSON as well as XML.
- {{Mono|jq}} is like {{Mono|sed}} for JSON data – it can be used to slice and filter and map and transform structured data.
References
{{reflist}}