JSONPath Cheat Sheet
Query JSON documents with JSONPath selectors and filters.
Core Syntax
| Key / Code | Description |
|---|---|
| $ | Root element |
| .name | Child member |
| ..name | Recursive descent |
| [*] | All array elements |
| [0] | Array index |
| [?()] | Filter expression |
| @ | Current node in filters |
Filter Examples
| Key / Code | Description |
|---|---|
| $.users[?(@.active)] | Active users |
| $.orders[?(@.total > 100)] | Orders over 100 |
| $.items[?(@.tags.indexOf('new') >= 0)] | Items tagged 'new' |
Tips
Different libraries vary slightly. Check your JSONPath implementation for supported operators.
When to Use JSONPath
Use JSONPath when you need to inspect API responses, extract nested fields from large payloads, or build lightweight assertions in tests and automation scripts without writing full parser code.
Common JSONPath Mistakes
The biggest source of confusion is library differences: not every implementation supports the same filter syntax, script expressions, or functions. Another frequent issue is forgetting whether the expression should return a scalar value, a node list, or an array of matches.
Related
Knowledge is power.