Software:JSONPath: Difference between revisions

From HandWiki
(import)
 
No edit summary
 
Line 1: Line 1:
<!-- Do not remove this line! -->
----
{{Short description|A standard syntax for querying JSON values}}
{{Short description|A standard syntax for querying JSON values}}
{{Draft topics|software|computing|technology}}
{{AfC topic|other}}


JSONPath is a [[Domain-specific language|domain specific language]] for querying values in [[JSON]] objects. The uses of JSONPath include:
'''JSONPath''' is a [[Domain-specific language|domain specific language]] for querying values in [[JSON]] objects. The uses of JSONPath include:


* Selecting a specific node in a JSON value
* Selecting a specific node in a JSON value

Latest revision as of 18:19, 24 March 2024

Short description: A standard syntax for querying JSON values


JSONPath is a domain specific language for querying values in JSON objects. 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 written as strings, e.g. $.foo.

Example

The JSONPath expression $.store.book[0] applied to the following value selects the first book (by Nigel Rees).

{
  "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
    }
  }
}

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 RFC 9535.[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.
  • JSON Pointer[9] defines a string syntax for identifying a single value within a given JSON value of known structure.
  • JSONiq[10] is a query and transformation language for JSON.
  • XPath3.1[11] is an expression language that allows the processing of values conforming to the XDM[12] data model. The version 3.1 of XPath supports JSON as well as XML.

References

  1. Gössner, Stefan. "JSONPath - XPath for JSON". https://goessner.net/articles/JsonPath/. 
  2. Burgmer, Christoph. "JSONPath Comparison". https://cburgmer.github.io/json-path-comparison/. 
  3. Friesen, Jeff (11 January 2019). "Extracting JSON values with JsonPath". Java XML and JSON: Document Processing for Java SE (2nd ed.). Apress. ISBN 978-1484243299. 
  4. Gössner, Stefan; Normington, Glyn; Bormann, Carsten (February 2024). RFC 9535 JSONPath: Query Expressions for JSON. The Internet Engineering Task Force (IETF). https://www.rfc-editor.org/rfc/rfc9535. Retrieved 22 March 2024. 
  5. Jiang, Lin; Sun, Xiaofan; Farooq, Umar; Zhao, Zhijia (April 2019). "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. 79–92. doi:10.1145/3297858.3304008. ISBN 978-1-4503-6240-5. 
  6. Gienieczko, Mateusz; Murlak, Filip; Paperman, Charles (February 2024). "Supporting Descendants in SIMD-Accelerated JSONPath". Conference on Architectural Support for Programming Languages and Operating Systems 4. 
  7. Brahmia, Zouhaier; Grandi, Fabio; Brahmia, Safa; Bouaziz, Rafik (2023). "τJSONPath: A Temporal Extension of the JSONPath Language for the τJSchema Framework". Artificial Intelligence and Smart Environment. Lecture Notes in Networks and Systems. 635. pp. 844–853. doi:10.1007/978-3-031-26254-8_123. ISBN 978-3-031-26253-1. 
  8. Saryerwinnie, James. "JMESPath". https://jmespath.org/. 
  9. Bryan, Paul; Zyp, Kris; Nottingham, Mark (April 2013). RFC 6901 JavaScript Object Notation (JSON) Pointer. The Internet Engineering Task Force (IETF). https://www.rfc-editor.org/rfc/rfc6901. Retrieved 23 March 2024. 
  10. "JSONiq". https://www.jsoniq.org/. 
  11. Robie, Jonathan; Dyck, Michael; Spiegel, Josh. "XML Path Language (XPath) 3.1". https://www.w3.org/TR/xpath-31/. 
  12. Tovey-Walsh, Norman; Snelson, John; Coleman, Andrew. "XQuery and XPath Data Model". https://www.w3.org/TR/xpath-datamodel-31/.