JSONPath helps with the querying, analysing and transformation of JSON and JavaScript objects.
This library is distributed under the MIT license, its source and full documentation can be found at www.npmjs.com/package/jsonpath-plus (opens new window).
Executed
Server-side
Details
var JsonPath = require('jsonpath-plus');
At its simplest the result is expressed as
var result = JSONPath({json: obj, path: path});
Where obj is the name of the JSON object to evaluate and path is the JSONPath expression. See the www.npmjs.com/package/jsonpath-plus (opens new window) documentation for detailed examples of path expressions.
Example
An extended example of JsonPath is included in the GOSS.Examples.NodeModules group of the End Point library.
function(params, credentials) {
var JsonPath = require('jsonpath-plus'),
result = null,
json = {
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"price": 8.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"price": 22.99
}
],
"bicycle": {
"colour": "red",
"price": 19.95
}
}
};
result = JsonPath({json: json, path: "$.store.book[*].author"});
return result;
}
{
"jsonrpc": "2.0",
"id": 25,
"result": ["Nigel Rees", "Evelyn Waugh", "Herman Melville", "J. R. R. Tolkien"]
}