Document Workflow
How to extract values from a JSON response with JSONPath
Use JSONPath to pull IDs, emails, totals, and nested fields from API responses without uploading the payload or writing a temporary script.
Written and tested by SimpleWebUtilsPublished: Reviewed:
How this workflow was checked
For the JSONPath Tester - Query and Extract JSON Values review, we preserved the source shown in “Extract a user email and order IDs from an API response” and completed “Paste the JSON response” and “Move the extracted values into the next tool”. The produced output was compared literally where possible, with “Skipping JSON validation” and “Using a broad recursive selector too early” checked against the linked failure evidence.
The selected paths returned dev@example.com and both order IDs, and the normalized concrete paths identified the two array elements without exposing unrelated totals. Using $.orders[*].id instead of $..id also avoided matching user.id, while copied results still required redaction before sharing. Wildcard results retained source-array order, while malformed JSON and a missing member remained distinguishable from a legitimate empty string.
Problem
Large API responses often contain the value you need several levels below the root object. Scrolling through formatted JSON works for one field, but it breaks down when you need every order ID, every user email, or the same nested property across a list of records.
Sources and standards
These authoritative references define the formats or security boundaries used in this workflow. Tool-specific verification is documented separately above.
- RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format
RFC Editor / IETF
- RFC 9535: JSONPath: Query Expressions for JSON
RFC Editor / IETF
When to use this
- An API response contains nested user, order, product, or event data and you need one field quickly.
- A QA report needs a repeatable JSONPath expression instead of a screenshot of a large payload.
- A spreadsheet or ticket needs only selected fields from a larger response.
- You want to verify a JSONPath expression before adding it to monitoring, tests, or documentation.
Steps
- Step 1
Format or validate the response first
Start with valid JSON. If the response is minified or hard to read, use JSON Formatter or JSON Validator before testing expressions.
- Step 2
Paste the JSON response
Copy the response body from DevTools, curl, an API client, or logs and paste it into JSONPath Tester. Redact tokens and user identifiers if the output will be shared.
- Step 3
Write a focused JSONPath expression
Use paths such as $.user.email, $.orders[*].id, or $.orders[?(@.total >= 20)].id to target one field, every array item, or records that satisfy a filter.
- Step 4
Review matches and paths together
Check both the extracted values and their source paths. The path tells you whether the expression matched the intended object or a similarly named field elsewhere.
- Step 5
Move the extracted values into the next tool
Copy the focused result into JSON to CSV when the values need spreadsheet review, or keep the expression with your debugging notes for repeatable checks.
Example
Extract a user email and order IDs from an API response
Input
{
"user": { "id": 42, "email": "dev@example.com" },
"orders": [
{ "id": "ord_1001", "total": 49.5 },
{ "id": "ord_1002", "total": 19.0 }
]
}Output
$.user.email -> dev@example.com
$.orders[*].id -> ord_1001, ord_1002
Normalized paths: $['user']['email'], $['orders'][0]['id'], $['orders'][1]['id']Common mistakes
Skipping JSON validation
A broken comma or quote can make a valid-looking expression appear wrong. Validate the payload before changing the JSONPath expression.
Using a broad recursive selector too early
Expressions such as $..id can match user IDs, order IDs, and unrelated identifiers. Start with a specific path, then broaden it only when needed.
Copying sensitive values into shared notes
The extraction runs in the browser, but copied output can still expose emails, tokens, or account IDs. Redact before pasting results into tickets.
FAQ
What is JSONPath useful for?
JSONPath is useful when you need to select fields from nested JSON without writing a one-off script. It is especially helpful for API responses, logs, fixtures, and test data.
Can JSONPath extract values from arrays?
Yes. Use an index such as $.orders[0].id for one item, or a wildcard such as $.orders[*].id when you need the same field from every item. Review the returned source paths as well as the values before exporting the result.
Should I use JSONPath before or after formatting JSON?
Use JSON Formatter or JSON Validator first when the response is minified or may be invalid. Then use JSONPath Tester to extract the exact fields you need.