> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# JSON Path 2 Wild Cards

> Guide explaining JSONPath wildcard operator for objects and arrays, using * and [*], including recursive descent, examples, and practical tips for querying nested JSON

Hello — welcome to this JSONPath demo.\
My name is Mumshad Mannambeth. This lesson extends the basics of JSONPath by focusing on the wildcard (star) operator and how it behaves with both objects and arrays.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/RMI5Z0UHsJ07Jee-/images/JSON-Path-Test-Free-Course/Lesson/JSON-Path-2-Wild-Cards/orange-json-path-part2-wildcard.jpg?fit=max&auto=format&n=RMI5Z0UHsJ07Jee-&q=85&s=06e043ed16e77c17b5c1bf3714fa41f1" alt="An orange presentation slide with the title &#x22;JSON PATH&#x22; and the subtitle &#x22;PART - 2 - WILD CARD.&#x22; Faint network node graphics appear in the background and a small circular timer marked &#x22;22&#x22; is in the top right." width="1920" height="1080" data-path="images/JSON-Path-Test-Free-Course/Lesson/JSON-Path-2-Wild-Cards/orange-json-path-part2-wildcard.jpg" />
</Frame>

Overview

* The wildcard (`*`) selects all properties at an object level or all elements in an array.
* Use `.*` for object-level wildcards and `[*]` for array wildcards.
* The recursive-descent operator (`..`) can find matching fields anywhere in the JSON tree (use it when the nesting depth is unknown).

Object wildcard examples
We reuse a simple top-level object with two child objects, `car` and `bus`. Each child has `color` and `price`.

Example JSON:

```json theme={null}
{
  "car": {
    "color": "blue",
    "price": "$20,000"
  },
  "bus": {
    "color": "white",
    "price": "$120,000"
  }
}
```

Get the color of the car:

```text theme={null}
$.car.color
```

Result:

```json theme={null}
[ "blue" ]
```

Get the color of the bus:

```text theme={null}
$.bus.color
```

Result:

```json theme={null}
[ "white" ]
```

Get all colors without specifying `car` or `bus` by using the object wildcard:

```text theme={null}
$.*.color
```

Result:

```json theme={null}
[ "blue", "white" ]
```

<Callout icon="lightbulb" color="#1CB2FE">
  The `*` wildcard selects all properties at the current object level. In the example above, `$.*.color` retrieves the `color` property from every top-level property (such as `car` and `bus`).
</Callout>

Array wildcard examples
Consider an array of wheel objects; each wheel has a `model` and `location`.

Example JSON (array of objects):

```json theme={null}
[
  {
    "model": "X345ERT",
    "location": "front-right"
  },
  {
    "model": "X346ERT",
    "location": "front-left"
  },
  {
    "model": "X347ERT",
    "location": "rear-right"
  },
  {
    "model": "X348ERT",
    "location": "rear-right"
  }
]
```

Get the model of the first wheel (index 0):

```text theme={null}
$[0].model
```

Result:

```json theme={null}
[ "X345ERT" ]
```

Get the model of the fourth wheel (index 3):

```text theme={null}
$[3].model
```

Result:

```json theme={null}
[ "X348ERT" ]
```

Get the models of all wheels in the list using the array wildcard `[*]`:

```text theme={null}
$[*].model
```

Result:

```json theme={null}
[ "X345ERT", "X346ERT", "X347ERT", "X348ERT" ]
```

Within arrays, `[*]` means "every item in the array."

Combining object and array wildcards
Now combine both patterns: a top-level object with `car` and `bus`, each containing a `wheels` array.

Example JSON (nested structure):

```json theme={null}
{
  "car": {
    "color": "blue",
    "price": 20000,
    "wheels": [
      {
        "model": "X345ERT"
      },
      {
        "model": "X346ERT"
      }
    ]
  },
  "bus": {
    "color": "white",
    "price": 120000,
    "wheels": [
      {
        "model": "Z227KLJ"
      },
      {
        "model": "Z226KLJ"
      }
    ]
  }
}
```

Get the model of the first wheel of the `car`:

```text theme={null}
$.car.wheels[0].model
```

Result:

```json theme={null}
[ "X345ERT" ]
```

Get the models of all wheels of the `car`:

```text theme={null}
$.car.wheels[*].model
```

Result:

```json theme={null}
[ "X345ERT", "X346ERT" ]
```

Get the models of all wheels of the `bus`:

```text theme={null}
$.bus.wheels[*].model
```

Result:

```json theme={null}
[ "Z227KLJ", "Z226KLJ" ]
```

Get the models of all wheels across `car` and `bus` by using both object and array wildcards:

```text theme={null}
$.*.wheels[*].model
```

Result:

```json theme={null}
[ "X345ERT", "X346ERT", "Z227KLJ", "Z226KLJ" ]
```

<Callout icon="warning" color="#FF6B6B">
  The recursive-descent operator `..` searches the entire document for matching field names at any depth. Use it when you don't know the exact nesting, but be aware it can return broader results than a targeted wildcard. For the example above, `$..wheels[*].model` finds the same wheel models but will also match `wheels` fields deeper in other branches of a larger document.
</Callout>

Quick reference table

| Operator | Description | Example |
| - | - | - |
| Object wildcard | Selects all properties on the current object level | `$.*.color` |
| Array wildcard | Selects every item in an array | `$[*].model` |
| Array index | Selects a specific array element by index | `$[0].model` |
| Recursive-descent | Finds matching fields at any depth | `$..wheels[*].model` |

Practical tips

* Build queries incrementally: query a single branch (e.g., `$.car`) first, verify results, then generalize with `*` once you understand the structure.
* Prefer targeted wildcards (`$.*.field` or `$.path[*].field`) for predictable output; use `..` only when necessary.
* Combine object and array wildcards to flatten nested collections (e.g., `$.*.wheels[*].model`).

Links and references

* JSONPath overview and syntax: [https://goessner.net/articles/JsonPath/](https://goessner.net/articles/JsonPath/)
* JSONPath examples and tools: [https://github.com/json-path/JsonPath](https://github.com/json-path/JsonPath)

That's it for this lesson — try these queries on different JSON samples to see how the wildcard and recursive-descent operators behave.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/json-path-test-free-course/module/114e6dee-a9f2-49f3-a0c6-cdfb92f74310/lesson/4ee22714-9402-46bf-aca6-e96b9b3428ba" />

  <Card title="Practice Lab" icon="flask-conical" cta="Learn more" href="https://learn.kodekloud.com/user/courses/json-path-test-free-course/module/114e6dee-a9f2-49f3-a0c6-cdfb92f74310/lesson/6554e5ac-4380-4798-8b2b-01bf77f61fd3" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.