SheepDev

Data and structured data

Extract only the fields you need from an API response

Tools to use

You want product names from an API response for a meeting note. Searching for name works until a customer's name appears in the same response or one product lacks that field. Manual copying then becomes unreliable. A useful extraction identifies both a field and where it belongs.

We will use a fictional product list. JSONPath selects values at locations; it does not need to rewrite the source. Instead of starting with a complicated expression, narrow the selection from the whole document to the list, one item, and then its name. That makes an empty result easier to investigate.

Supply the response body, not its URL

This tool is not an API client. It does not fetch a pasted URL, log in, or locate subsequent pages. Supply the response body and paste only its JSON portion; HTTP status lines and headers are not JSON. For a shared example, use fictional data with the same structure instead of a production response containing real names or tokens.

The result describes the supplied input, not a live API. Later server changes do not automatically refresh it. If freshness matters, record which response you examined in your own work notes. Obtaining the source and extracting from supplied JSON are separate stages.

Use data containing both product and owner names

Paste into the JSON input
{"items":[{"id":"A","name":"Notebook","price":500},{"id":"B","name":"Pencil","price":120},{"id":"C","name":null,"price":300}],"owner":{"name":"Demo team"},"page":1}

Open JSONPath extraction and paste this into the JSON field. Enter only $ in the separate expression field and run it to select the entire document as one result. If that fails, check JSON brackets and quotes before complicating the expression. Keep the document and expression in their separate fields; appending the expression to the JSON makes a different, invalid input.

The outer result array does not mean the source was rewritten into an array. This tool returns a list of selected values. Selecting the whole document produces a one-element result list. Distinguish that wrapper from the original items array; this also explains nested brackets in later selections.

Move from one item to its name

Expression: first product name
$.items[0].name
Expected result
["Notebook"]

$ identifies the document, items selects its list, [0] selects the first item, and name selects that product's field. The first index is zero, not one. Changing it to [1] selects Pencil; [2] selects null. Compare each index with the source position to understand the path rather than merely memorize it.

If the full path does not work, test $.items and then $.items[0] separately. Match the exact field spelling, including case. Check what the source actually calls the field rather than guessing between items and Items. An empty selection is not a reason to rename source fields.

Replace repeated copying with a wildcard

Expression: each product's name
$.items[*].name
Expected: owner name is excluded
["Notebook","Pencil",null]

Replacing [0] with [*] applies the selection to every list element. Because the path stays within items, owner.name is excluded. Unlike a text search for name, the expression records that you wanted names belonging to products. That makes the extraction easier to explain and repeat on similarly structured responses.

Three results do not prove the server has only three products. The example contains page, but this tool does not fetch the next page. It can inspect only the response you supplied. If you need a complete export, separately check the source API's pagination and result limits.

An empty result is not a null result

$.items[2].name yields [null]: the third item has a name field whose value is null. $.items[3].name yields [] because no fourth item exists. The first is one selected value; the second is no selected value. Reporting both as 'the value was null' erases the distinction between explicit null and absence.

A separate document containing an empty array
{"items":[]}

For this separate document, $.items yields [[]] because it selects one value that happens to be an empty array. $.items[*] yields [] because that array contains no elements. Instead of counting brackets, ask what counts as one selected value. An empty result does not by itself mean the expression is broken.

Separate extractions can lose row alignment

The second item has no name field
{"items":[{"id":"A","name":"Notebook","price":500},{"id":"B","price":120},{"id":"C","name":"Eraser","price":300}]}

Names yield Notebook and Eraser, while prices yield 500, 120, and 300. Pairing the second name with the second price would incorrectly assign 120 to Eraser. Do not assume missing fields are replaced by empty placeholders. Different result counts can reveal missing source fields, not merely a formatting inconvenience.

To preserve the relationship, select whole product objects with $.items[*] and retain their ids. For a table, convert fields belonging to the same object into columns rather than joining independently extracted lists by row number. When moving to JSON–CSV conversion, also check how missing fields and null are represented.

Try against the original document
$..name

Returning to the original document, this also selects Demo team. A recursive search is useful for discovering fields at unknown depths, but values alone do not clearly identify their origins. Search broadly while investigating, then narrow to $.items[*].name once you know the intended location.

Avoid broad recursive searches over unnecessarily large inputs. The tool has limits such as a maximum result count; exceeding them is not a promise to return a complete result in shortened form. Verify the expression on a small representative sample before applying it to the actual input, separating selection mistakes from workload limits.

When an online example fails, check the supported syntax

JSONPath has a standardized specification as well as implementation extensions. SheepDev disables arbitrary code evaluation and rejects filter and script expressions. A price-condition expression copied from another site may therefore be unsupported. A rejected expression is not evidence that no products matched its condition.

After extraction, check the source scope, selected fields, and result count. Include the expression and scope when handing off results. 'Two existing name values extracted from this page's items' is more informative than 'two product names' and makes omissions or accidental inclusion from another branch easier to investigate.

Sources

Tools to use

Guides →