Query JSON with JSONPath
What JSONPath does to your JSON, what it never changes, where implementations disagree, and when a plain-text or different tool is the better choice.
JSONPath is a query syntax for picking values out of a JSON document. You write an expression such as $.orders[*].id and get back the matching values. This review covers three questions: whether JSONPath fits your task, what it actually changes, and whether its results stay accurate once you copy or share them. No specific JSONPath tool was tested for this article, so the review covers the query language and the general behavior of tools that implement it, not any single product.
Is JSONPath suitable for your use?
JSONPath is a good fit when you need to read or check values inside a JSON document without writing code. Typical cases are inspecting an API response, confirming that a field exists, or listing every value of one key across a nested structure. Its main benefit is that one short expression can reach deep into nested arrays and objects and return every match at once.
The main limitation is that JSONPath only selects. It cannot rename keys, compute new fields, or reshape the output into a different structure. Implementations have also historically disagreed on details. An expression that works in one tool can fail or return different results in another, especially for filters, functions, and how results are presented.
Plain text or a different approach is better in these situations:
- You need one known location. A JSON Pointer such as /orders/0/id is simpler and names exactly one value.
- You need to transform or restructure data. A transformation language such as jq, or a short script, is the right tool.
- You are sharing results with people who do not read JSON. A plain-text summary or a table of the values is clearer than raw query output.
- The expression must behave the same across several systems. In that case, test it in each one rather than assuming portability.
What a JSONPath query actually changes
Running a query does not modify the source document. Unlike the text transformations covered elsewhere in this category, such as reversing, mirroring, or Unicode font substitution, JSONPath changes no characters in what you stored. It produces a new, separate result: a list of the values (nodes) that matched. Some tools return the location of each match instead of its value, or alongside it, written as a normalized path such as $['orders'][0]['id'].
Several terms near JSONPath are easy to confuse:
- JSON Pointer is a separate, simpler standard. It addresses exactly one location using slash-separated keys and has no wildcards or filters.
- jq and JMESPath are separate query languages with different syntax. Both can build new output structures, which JSONPath does not do.
- Formatting or pretty-printing changes only whitespace and indentation. It is a display change, not a query.
- The original JSONPath proposal was informal, and libraries filled the gaps in different ways. The IETF has since published a standard version as RFC 9535. Not every tool follows it, so check which variant a tool implements.
Core syntax
- $ refers to the root of the document.
- .name or ['name'] selects an object member. Use the bracket form for keys that contain spaces or punctuation.
- [0] selects an array element by index. In the standard form, [-1] selects the last element.
- [*] selects all children of an object or array.
- [start:end] selects a slice of an array, where end is exclusive.
- .. searches all descendants. For example, $..sku finds every sku key at any depth.
- [?expression] keeps only the children for which the expression is true. Inside the expression, @ refers to the child being tested. Older tools often require parentheses, as in [?(@.total > 20)]. That form is also valid under the standard because parentheses are allowed for grouping.
Worked example
The sample document below is used for the queries in the table that follows. Results are written as JSON arrays of matched values, which is how many tools display them. The results were derived by applying the standard's rules by hand, not by running a particular tool.
{
"orders": [
{"id": "A-1", "status": "shipped", "total": 42.5, "items": [{"sku": "pen", "qty": 3}]},
{"id": "A-2", "status": "pending", "total": 18, "items": [{"sku": "pad", "qty": 1}, {"sku": "pen", "qty": 2}]},
{"id": "A-3", "status": "shipped", "total": 7.25, "items": []}
]
}
| Query | Result | Note |
| $.orders[*].id | ["A-1", "A-2", "A-3"] | Wildcard over the array |
| $.orders[-1].id | ["A-3"] | Negative index; unsupported by some older tools |
| $.orders[0:2].total | [42.5, 18] | Slice end is exclusive |
| $..sku | ["pen", "pad", "pen"] | Descendant search; duplicates are kept |
| $.orders[?@.status == 'shipped'].id | ["A-1", "A-3"] | Filter on a string value |
| $.orders[?length(@.items) == 0].id | ["A-3"] | length() is a standard function; older tools may reject it |
Even a single match comes back as a one-item list, not a bare value. If no node matches, the result is an empty list rather than an error. Scripts that expect a single value, or expect a failure on a missing field, need to account for both cases.
Will results stay accurate after copying or sharing?
JSONPath output is ordinary JSON text, so it usually copies cleanly. A few details can still change the meaning or make results misleading:
- Copy formatting. Some tools display matches as separate lines or tree nodes instead of one JSON array. Copying from those views can drop quotes or brackets, which makes strings, numbers, and booleans hard to tell apart. Copy the raw JSON output when the exact value types matter.
- Numbers. Serializers may write 18 as 18.0 or change how decimals are formatted. Tools that run in JavaScript can silently lose precision on integers above about 9 quadrillion (2^53). Check large IDs carefully.
- String escapes. A value stored as \u00e9 may be displayed as é. The meaning is the same, but a byte-for-byte or text comparison will differ.
- Unicode comparison. Under the standard, filters compare strings code point by code point, without Unicode normalization. An é stored as one precomposed character does not equal an e followed by a combining accent, even though both look identical. A filter can therefore miss values that appear to match.
- Object member order. JSON does not define an order for object members. When .. or [*] walks an object, the order of results may differ between tools. Array order is preserved.
- Portability. Filters, functions, and negative indexes are where implementations diverge most. Record the tool and variant when you share an expression.
Accessibility: no testing with screen readers or other assistive technology was available for this review, so no claims are made about how any specific tool's interface reads aloud. Plain-text JSON can at least be read and edited in any text editor. Collapsible tree views depend on how each tool builds its interface. When sharing with a mixed audience, provide the plain-text result or a short written summary of the values.
Privacy: pasting a document into a web-based JSONPath tester sends its contents to a page whose data handling you cannot judge from its appearance. For documents containing credentials, personal data, or internal records, use a local tool or library unless the service's documentation clearly describes how input is stored and retained.
Gaps in this review
No specific JSONPath tool, library, or service was evaluated. As a result, this article has no performance figures, no tool-by-tool compatibility results, and no assistive-technology test results. Statements about behavior describe the standardized language and well-known differences between implementations. Before relying on an expression, test it in the exact tool or library you will use.