Short answer
Use JSONPath for standardised JSON selection, jq when the path belongs in a command-line transformation, and JavaScript property access when the destination is application code.
Key points
- The same selected value can be represented in several path syntaxes.
- Keys with punctuation or spaces require bracket or quoted notation.
- Copying from the tree avoids transcription errors in long paths.
One value, three destinations
Suppose an API response contains an email under the first user’s profile. A support note, a shell command and frontend code may all refer to the same value, but each context expects different syntax.
{
"users": [
{
"profile": {
"email": "ada@example.test"
}
}
]
}| Use | Path |
|---|---|
| JSONPath | $.users[0].profile.email |
| jq | .users[0].profile.email |
| JavaScript | data?.users?.[0]?.profile?.email |
JSONPath selects values
JSONPath is standardised in RFC 9535. It begins at the root with $ and can select object members, array elements, slices and filtered descendants. It is useful in test tools, API clients and systems that explicitly accept JSONPath.
A simple copied path identifies one value. More advanced JSONPath expressions can select several values, so do not assume every expression behaves like a unique object address.
jq is a processing language
jq paths often resemble JSONPath after the root marker, but jq is a complete command-line processing language. The path may be the first step in a filter, projection or transformation.
Use the copied jq path as a reliable starting point, then add the operation the script needs. For example, .users[].profile.email streams the email value for each user.
JavaScript paths belong in code
Optional chaining is useful when application code must tolerate a missing intermediate value. It returns undefined instead of throwing when an optional access encounters null or undefined.
Keys that are not valid JavaScript identifiers need bracket notation. A key named feature.flag becomes data?.["feature.flag"], not data?.feature.flag.
Copy from selection instead of retyping
Long paths are easy to mistype, especially around array indexes and keys that need quoting. Blobster lets you select a tree node, table cell or search result and copy JSONPath, jq or JavaScript syntax from the same inspector.
The copied path describes the current document. If the schema is unstable or an array order changes, verify that an index-based path is still the right reference.