Developer 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.
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.
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 $..status to target one field, every array item, or a recursively nested property.
- 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
Matched paths: $.user.email, $.orders[0].id, $.orders[1].idCommon 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.
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.