JSONPath

JSONPath
ParadigmQuery language
Designed byStefan Gössner
DeveloperStefan Gössner
First appeared2007 (blogged)
2024 (standardized)
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
Websitewww.rfc-editor.org/rfc/rfc9535

In computer software, JSONPath is a query language for querying values in JSON. The uses of JSONPath include:

JSONPath queries are path expressions written as strings, e.g. $.foo.

Example

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

JSONPath was first described in an online article 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. JSONPath is widely used in the Java ecosystem.

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

Research

Alternatives