An API response lands in front of you with an array of two hundred products, and you need every price. Writing one path per item is not a plan, and pasting the response into a spreadsheet to read it by eye is barely better. JSONPath has a single step built for exactly this: the wildcard, written [*]. One wildcard selects every item in the array, and one field name after it collects that field from each item.

This guide explains what the wildcard selects, how it differs from a plain index like [0], and how it behaves on objects, using the free JSONPath Tester on Ovatly, which runs in your browser against the JSON you paste.

Contents

  • Quick answer
  • What the wildcard actually selects
  • Wildcard or index: [*] against [0]
  • Collecting one field from every item
  • How to select all items, step by step
  • Worked example: every book title in the store
  • Limitations and honest tradeoffs
  • Common mistakes
  • FAQs
  • Conclusion
  • References

Quick answer

To select all items in an array with JSONPath, put [*] where an index would normally go: $.store.book[*] selects every book in the array. Add a field name to collect that field from each item: $.store.book[*].title returns the title of every book. In the JSONPath Tester, paste your JSON, type the path and read the matches. The wildcard works on objects too, where it selects every value the object holds.

What the wildcard actually selects

A JSONPath expression walks from the root, written $, down through the structure one step at a time. Most steps name one thing: .store names the store key, .book names the book key, and [0] names the first item of an array. The wildcard is the step that names everything at that level instead.

Written after an array, [*] selects each item in turn, and the rest of the path is applied to every one of them. Written after an object, it selects each value the object holds. Nothing is filtered or changed: the wildcard is a selection step, not a condition.

That makes it the natural partner of the field step. On its own, [*] hands you whole items. Followed by .title, it hands you one field per item: every title, every price, every status in the list.

The wildcard also works on objects: $.store.book[0][*] selects every value the first book holds, title and author alike, without naming a key. Useful for inspecting an object whose field names you do not know yet; the trade is precision, since a named key returns exactly one thing.

Wildcard or index: [*] against [0]

[0] is a position. It selects exactly one item, the first, because JSONPath counts array positions from zero. [1] selects the second, and so on. An index is the right step when the item you want is defined by where it sits: the newest entry in a newest-first feed, or the primary address in a list where the first is the main one.

[*] is a sweep. It selects every item regardless of position, so the result grows with the array: two items give two matches, two hundred give two hundred. Reach for the index when "the first one" is genuinely the rule. Reach for the wildcard when the question is about the array as a whole, because an index quietly answers a different question than the one you asked, and answers it correctly, which is what makes the mistake so hard to spot.

Collecting one field from every item

The pattern you will use most is wildcard first, field second:

$.store.book[*].title

Read it left to right. $ is the root of the document. .store steps into the store object. .book steps into the array. [*] selects every item in it. .title reads the title field from each selected item. The result is a list of titles, one per book, in the order the books appear in the array.

The same pattern works at any depth and for any field: swap .title for .author and you collect authors instead. Add a further step and you can keep walking into each item, so if every book held a list of formats, a second wildcard would collect across those lists too.

How to select all items, step by step

  1. Open the JSONPath Tester and paste the JSON you want to query, whether that is the store document below or a real response.
  2. Start the path with $ for the root, then walk to the array with named steps, such as .store.book.
  3. Add [*] where the index would go. Run the path as it stands to see every whole item the wildcard selects.
  4. Add the field you want from each item, such as .title, and run it again. The result is now one value per item.
  5. Read the matches. If the list is shorter than the array, a step before the wildcard is landing somewhere narrower than you intended, so rebuild the path a step at a time.

Worked example: every book title in the store

Here is the store document used throughout this guide:

{
  "store": {
    "book": [
      { "title": "Dune", "author": "Frank Herbert" },
      { "title": "Emma", "author": "Jane Austen" }
    ]
  }
}

Three paths against it show the whole idea. $.store.book[0] returns the first book only, the Dune object, because [0] is a position. $.store.book[*] returns both book objects, because the wildcard sweeps the whole array. And $.store.book[*].title returns:

Dune, Emma

Two titles from one short path. Nothing in the path mentions how many books there are, so the same expression keeps working when the array grows to three books or three hundred: the wildcard absorbs the count.

Limitations and honest tradeoffs

The tester covers a defined subset of JSONPath, and the wildcard sits inside it, but some neighbouring steps do not. Filter expressions such as [?(...)], which select items by a condition, are not supported, and neither are slices such as [0:2], scripts or unions. If a path uses an unsupported part, the tester stops and names that part in a clear error rather than guessing, so you know exactly which step to rewrite.

The wildcard also has no opinions. It cannot pick the cheapest or newest item: it selects all of them, and any choosing happens before or after. And a path that matches nothing returns zero matches, a valid result rather than an error; an empty result after a wildcard usually means an earlier step landed in the wrong place.

Common mistakes

  • Using [0] out of habit. The path returns a plausible answer, the first item, while the question was about all of them. If your sentence contains "every" or "all", the path needs the wildcard.
  • Putting the field before the wildcard. $.store.book.title[*] asks for a title key on the array itself, which is not there. The wildcard selects the items first, then the field is read from each.
  • Expecting the wildcard to filter. [*] never tests a condition. It cannot return only the books under a price, because filters are unsupported in this tester.
  • Reading an empty result as a crash. Zero matches is a valid answer: the path selects nothing in this data, which is information, not a tool failure.

FAQs

What does [*] do in a JSONPath expression? It is the wildcard. After an array it selects every item at once, and after an object it selects every value the object holds. A field name written after it, as in $.store.book[*].title, is then collected from each selected item.

What is the difference between [*] and [0]? [0] is an index: it selects only the first item of an array. [] selects every item. On a two-book array, $.store.book[0].title returns the first title only, while $.store.book[].title returns both titles.

Can I use the wildcard on an object instead of an array? Yes. The wildcard works on objects as well as arrays. Applied to an object it selects all of that object's values, so $.store.book[0][*] returns every value held by the first book, its title and its author alike.

How do I collect one field from every item? Put the field name directly after the wildcard. The path $.store.book[].title first selects every book with [], then reads the title field from each one, returning Dune and Emma for the store data used in this guide.

Is my JSON uploaded to a server when I test a path? No. The JSONPath Tester runs fully in your browser, so the JSON you paste and the expression you test stay on your device.

Conclusion

The wildcard is the step that turns JSONPath from a way to point at one value into a way to read a whole array: [*] selects every item, and the field after it is collected from each one. Keep indexes for questions about position, and let the wildcard handle questions about all of it. The JSONPath Tester runs every path in your browser, so you can experiment against real data freely. When a path comes back empty instead, our guide to JSONPath mistakes that return nothing walks through the usual causes, and the rest of the series lives in our Data and JSON Tools guides.

References