Schema and paths
JSONPath query guide with practical examples
Learn how to select properties, array records, recursive fields, slices, unions, and filtered values from JSON.
Document summary
A practical JSONPath reference that connects query patterns to real nested response structures.
Key takeaways
- Use strict, representative input before relying on output.
- Review structure, types, and edge cases instead of checking only visual formatting.
- Continue examples inside the connected Bacodev tool to verify the result.
Start every query from the root
The dollar symbol represents the complete JSON document. Add property names or array selectors to move through the structure.
Use the right selector
| Query | Purpose |
|---|---|
| $.user.name | Direct property |
| $[0] | First array item |
| $.items[*].id | One field from every record |
| Email fields at any depth | |
| $.items[0:5] | First five items |
| $.items[?(@.active==true)] | Basic filtered records |
Use bracket notation for unusual keys
Keys containing spaces, hyphens, dots, or leading numbers should use bracket notation such as $['order-id'].
Test queries against representative records
- 1
Load the complete structure.
- 2
Start with a direct path.
- 3
Add wildcard or recursion only where needed.
- 4
Check both matching and non-matching records.
- 5
Copy the exact path returned by the tool.
JSONPath implementations differ
JSONPath syntax in one table
JSONPath locates values inside a JSON document with a path expression, similar to how XPath works for XML. The same expression can be reused across tools and libraries that follow the common JSONPath conventions.
- $ selects the root of the document
- .name selects a property called name
- ..name finds every property called name at any depth
- [0] selects the first element of an array
- [*] selects all elements of an array
- $..book[?(@.price > 10)] filters books by a condition
Test a path before you use it in code
- 1
Open the JSONPath tester and paste your document.
- 2
Enter the expression you plan to use, for example $.items[0].name.
- 3
Check the matched results and the count against what you expect.
- 4
Refine the expression until it selects exactly the values you need.
Frequently asked questions
What is the difference between . and .. in JSONPath?
A single dot selects a direct child property; the double-dot recursive descent selects the property at any depth below the current node.
How do I filter array items in JSONPath?
Use a filter expression in brackets, for example $..items[?(@.status == "active")]. Filter operators include ==, !=, <, >, and logical && and ||.
Does JSONPath work the same in every library?
Most libraries follow the original JSONPath proposal, but some differ on filter syntax and functions. Test your expression in the tool before relying on it in code.
Is my JSON uploaded while testing paths?
No. The tester runs locally in your browser and never uploads the document.