Jump to content

JSONPath

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Glyn normington (talk | contribs) at 17:27, 23 March 2024 (History). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

JSONPath is a query language for JavaScript Object Notation (JSON).

A JSONPath query selects and extracts JSON values from a given JSON value. 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 query $.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 query $.store.book[*].price extracts the prices of books: 8.95 and 22.99 (since [*] selects all the nodes of an array).

The query $..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.

Subsequently, over fifty implementations were created in various programming languages. The JSONPath Comparison Project[2] lists many of these implementations and compares their behavior.

In 2024, the IETF published a proposed standard for JSONPath as RFC 9535[3].

Standards

JSONPath was standardised in 2024 as IETF RFC 9535[3].

Literature

  • Java XML and JSON: Document Processing for Java SE[4]
  • Supporting Descendants in SIMD-Accelerated JSONPath[5]
  • τJSONPath: A Temporal Extension of the JSONPath Language for the τJSchema Framework[6]

Alternatives

  • JMESPath[7] 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[8] defines a string syntax for identifying a single value within a given JSON value of known structure.
  • JSONiq[9] is a query and transformation language for JSON.

References

  1. ^ Gössner, Stefan. "JSONPath - XPath for JSON". Archived from the original on 11 September 2007. Retrieved 22 March 2024.
  2. ^ Burgmer, Christoph. "JSONPath Comparison". Archived from the original on 3 March 2024. Retrieved 22 March 2024.
  3. ^ a b Gössner, Stefan. "RFC 9535 JSONPath: Query Expressions for JSON". The RFC Series. The Internet Engineering Task Force (IETF). Retrieved 22 March 2024.
  4. ^ Friesen, Jeff (11 January 2019). Java XML and JSON: Document Processing for Java SE (2nd ed.). Apress. ISBN 978-1484243299.
  5. ^ 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.
  6. ^ Brahmia, Zouhaier; Grandi, Fabio; Brahmia, Safa; Bouaziz, Rafik (2023). "τJSONPath: A Temporal Extension of the JSONPath Language for the τJSchema Framework". Lecture Notes in Networks and Systems. 635.
  7. ^ Saryerwinnie, James. "JMESPath". Archived from the original on 14 March 2024. Retrieved 23 March 2024.
  8. ^ Bryan, Paul; Zyp, Kris; Nottingham, Mark. "RFC 6901 JavaScript Object Notation (JSON) Pointer". The RFC Series. The Internet Engineering Task Force (IETF). Retrieved 23 March 2024.
  9. ^ "JSONiq". Archived from the original on 13 January 2024. Retrieved 23 March 2024.