JSON Path Finder
Navigate and extract data from complex JSON structures using path notation. Find the exact path to any element in your JSON for use in code, queries, or data extraction.
JSON Path Notation
| Notation | Meaning | Example | $.propertyRoot property$.name .propertyChild property$.user.name [n]Array index$.items[0] [*]All elements$.items[*] | ..property | Recursive descent | $..name |
Path Examples
``javascript
const data = {
user: {
name: "John",
email: "john@example.com",
orders: [
{ id: 1, total: 99.99 },
{ id: 2, total: 149.99 }
]
}
};
// Paths to values:
// $.user.name → "John"
// $.user.email → "john@example.com"
// $.user.orders[0].id → 1
// $.user.orders[1].total → 149.99
// $.user.orders[*].total → [99.99, 149.99]
`
Path Implementation
`javascript
// Simple path extraction
function getValueByPath(obj, path) {
return path
.replace(/\[(d+)\]/g, '.$1')
.split('.')
.filter(Boolean)
.reduce((acc, key) => acc?.[key], obj);
}
// Usage
getValueByPath(data, 'user.orders[0].total'); // 99.99
getValueByPath(data, 'user.name'); // "John"
`
Using JSON Path Libraries
`javascript
// JSONPath library
const jsonpath = require('jsonpath');
// Query examples
jsonpath.query(data, '$.user.name');
// ["John"]
jsonpath.query(data, '$..total');
// [99.99, 149.99]
jsonpath.query(data, '$.user.orders[?(@.total > 100)]');
// [{ id: 2, total: 149.99 }]
``
Common Use Cases
| Use Case | Path Example | Access nested data$.data.users[0].profile API responses$.response.results[*] Configuration$.settings.database.host | Test assertions | expect($.data.id).toBe(1) |
Use this tool to find the correct path for any JSON element.