JSONPath

From Wikipedia, the free encyclopedia
(Redirected from Draft:JSONPath)
Jump to navigation Jump to search
JSONPath
ParadigmQuery language
Designed byStefan Gössner
DeveloperStefan Gössner
First appeared2007 (blogged)
2024 (standardized)
Website{{#property:P856}}
Influenced by
XPath
JSONPath
StatusProposed Standard
Year startedFebruary 2024 (2024-02)
OrganizationIETF
EditorsStefan Gössner
Glyn Normington
Carsten Bormann
AuthorsStefan Gössner
Base standardsJSON
Related standardsXPath

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

[edit | edit source]

The JSONPath expression $.store.books[0] applied to the following JSON value:

{
  "store": {
    "books": [
      { "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.books[*].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

[edit | edit source]

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

[edit | edit source]
  • 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

[edit | edit source]
  • 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.
  • jq is like sed for JSON data – it can be used to slice and filter and map and transform structured data.
  • ZPath[14] is a query language for structured data including JSON, CBOR and XML

References

[edit | edit source]
  1. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  2. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  3. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  4. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  5. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  6. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  7. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  8. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  9. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  10. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  11. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  12. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  13. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  14. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
[edit | edit source]