Table of Contents
JSONPath
Table of Contents
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
{ "name": "John Doe", "username": "johndoe", "email": "john@example.com"}
Structure
The entire object is wrapped in { }, which makes it a JSON object.
Inside the object, there are three key-value pairs (also called properties):
-
"name": "John Doe"- The key is"name"and the value is"John Doe"(a string). -
"username": "johndoe"- Key"username", value"johndoe". -
"email": "john@example.com"- Key"email", value“john@example.com”
| Expression | Description | Result |
|---|---|---|
$ |
The root object. | Whole JSON object |
$.name |
The value of the name property. | "John Doe" |
$.username |
The value of the username property. | "johndoe" |
$.email |
The value of the email property. | "john@example.com" |
For flat objects like this, each property is accessed by appending the key name to $ with a dot.