{"id":273,"date":"2018-05-01T10:46:38","date_gmt":"2018-05-01T10:46:38","guid":{"rendered":"https:\/\/restfulapi.net\/?p=273"},"modified":"2021-10-19T14:37:48","modified_gmt":"2021-10-19T09:07:48","slug":"json-jsonpath","status":"publish","type":"post","link":"https:\/\/restfulapi.net\/json-jsonpath\/","title":{"rendered":"JSON with JSONPath"},"content":{"rendered":"\n

JSONPath is a query language for JSON<\/a><\/strong> with features similar to XPath<\/a> for XML. JSONPath is used for selecting and extracting a sub-section from the JSON document.<\/p>\n\n\n\n

1. JSONPath Dependencies<\/h2>\n\n\n\n

To use JSONPath, we will need to include its dependency and then use it.<\/p>\n\n\n\n

Language<\/div><\/th>
Dependency<\/div><\/th><\/tr>
JavaScript<\/div><\/td>
Node<\/div><\/td>
npm install JSONPath<\/code><\/div><\/td><\/tr>
PHP<\/div><\/td>
Python<\/div><\/td>
pip install jsonpath-rw<\/code><\/div><\/td><\/tr>
Java<\/div><\/td>
json-path<\/a><\/div><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n

2. JSONPath Syntax<\/h2>\n\n\n\n

A JsonPath expression begins with the dollar sign ($<\/code>) character, which refers to the root element of a query. The dollar sign is followed by a sequence of child elements, which are separated via dot (code) notation or via the square brackets (code).<\/p>\n\n\n\n

The important JSONPath syntax rules<\/em> are:<\/p>\n\n\n\n