JSON path parser

Configuration options

  • JSON path - A JSONPath expression that selects values from a scraped JSON value. The expression must start with $, which stands for the whole JSON value.

Use JSON path when a scraped field contains JSON, for example a data attribute or a script value that holds structured product data.

Select a value

Example source:

{
  "name": "Packard 255 G2",
  "price": { "amount": 416.99, "currency": "USD" },
  "tags": ["sale", "new"],
  "specs": [
    { "k": "ram", "v": "4GB" },
    { "k": "processor", "v": "AMD E2" }
  ]
}

Configuration:

JSON path: $.price.amount

Result:

416.99

Other paths for the same source:

$.name                       → Packard 255 G2
$.tags[0]                    → sale
$.tags[-1]                   → new
$.specs[?(@.k=="ram")].v     → 4GB

The parser preview has CSV/XLSX and JSON tabs that show the result in each output format.

JSONPath basics used in Parser

Pattern Meaning
$ The whole JSON value.
.name The name field of an object.
["name"] The name field, written with brackets.
[0] The first item of an array.
[-1] The last item of an array.
[0,1] The first and second items of an array.
[*] All items of an array.
..name Every name field at any depth.
[?(@.k=="ram")] Array items whose k field is ram.
[?(@.price>400)] Array items whose price field is greater than 400.

Return an object or array

A path that selects an object or array returns it as JSON text in the CSV/XLSX output. In JSON output, it stays an object or array.

JSON path: $.price
Result: {"amount":416.99,"currency":"USD"}

Paths that match several values

Filters such as [?(@.k=="ram")], [*], .., slices such as [-1:] and lists such as [0,1] can match more than one value. In the CSV/XLSX output, the values are returned on separate lines. In JSON output, they are returned as an array, even when only one value matches.

JSON path:
$.tags[*]

Result in CSV/XLSX:
sale
new

Result in JSON:
["sale","new"]
JSON path:
$.specs[?(@.k=="ram")].v

Result in CSV/XLSX:
4GB

Result in JSON:
["4GB"]

To return a single value in every output format, select it by position, such as [0] or [-1].

Data types in JSON output

In JSON output, numbers and true or false values keep their type, and a number written as text, such as "416.99", stays text.

When nothing matches, or the value is null, the CSV/XLSX output is empty. In JSON output, a path that returns one value gives null, and a path that can return several values gives an empty array:

$.missing      → null
$.tags[5]      → null
$.missing[*]   → []

Values that are not JSON

The source value must be valid JSON. A value that is not, including JSON with single quotes or with other text around it, returns an empty value, or null in JSON output. Extract or clean the JSON with other parsers first. For example, a Regex match parser with the regex (?s)\{.*\} turns var product = {"name":"Packard 255 G2"}; into JSON that JSON path can read. The (?s) flag lets . match line breaks, so the regex also works when the JSON spans several lines.

Split one JSON field into several columns

Each parser returns one result. To create several columns from one JSON field, create a Virtual column for each field from the same source column:

name   ← product_json
price  ← product_json

Then add a JSON path parser to each Virtual column: $.name to name and $.price.amount to price.

When to use Regex match instead

Use Regex match when the source value is not valid JSON but the required value follows a predictable text pattern.

Troubleshooting

  • If every result is empty, check that the source value is valid JSON and that the path matches its structure, including letter case.
  • If the editor shows a JSONPath syntax error, such as expression must start with $ or unclosed bracket, the parser cannot be saved. Check that the path starts with $ and that every bracket is closed.
  • If one value contains several lines, or the JSON output shows an array, the path matched several values or used a filter. Select one value by position, such as [0].

Related