Skip to content
OddsockLocal
Local
Source text
{
  "color": "red",
  "count": 2
}
1 wordsRuns in this browser. Nothing is uploaded.

How to use

  1. Paste the JSON document into Source text.
  2. Type the expression in JSONPath. It must start with $.
  3. Use .key for an object key, [*] for every child, and [?(@.field>10)] for a comparison.
  4. Read the JSON array of matches.

What is JSONPath tester?

JSONPath tester evaluates one expression against the document and returns the matches as a JSON array. The path has to start with $. $ alone is the whole document, returned as a one-element array, which is what you get on {"color":"red","count":2} with the box left at its default. A dotted key such as $.count returns that value, still wrapped in an array.

Read more

$.items[*].name walks every element of items and collects name. On a document whose items are Notebook with qty 12 and Pen with qty 4, that expression returns ["Notebook", "Pen"]. A filter [?(@.qty>10)] keeps elements whose qty compares with the number you wrote, so $.items[?(@.qty>10)].name returns ["Notebook"]. Comparisons are ==, !=, >, <, >=, and <=. A path that does not start with $, or a construct the page does not implement, stops with a message that names the position.

Use cases

  • An API reviewer pulls every name from an items array with $.items[*].name.
  • A developer filters to rows with qty greater than 10 before looking at the rest of the payload.
  • Someone learning JSONPath runs $ on a small object and sees the document come back as a one-element array.
  • A support engineer extracts $.count from a logged body to confirm the number beside color.
  • Pasting items[*].name with the dollar sign left off shows the error that a path must start with $.

Names from an items array

Document: {"items":[{"name":"Notebook","qty":12},{"name":"Pen","qty":4}]}. JSONPath: $.items[*].name. The default path $ on {"color":"red","count":2} is the sample capture.

$.items[*].name returns [ "Notebook", "Pen" ]. $.items[?(@.qty>10)].name returns ["Notebook"]. The default $ on the color object returns [ { "color": "red", "count": 2 } ]. $.count on that object returns [2].

Why use Oddsock

The expression returns the values, as JSON, so $.items[*].name is something you can copy instead of folding the tree by hand.

Related tools

Using this tool

Every name under items. For Notebook qty 12 and Pen qty 4 the array is ["Notebook", "Pen"], in document order.