> For the complete documentation index, see [llms.txt](https://docs.ramsdenj.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ramsdenj.com/introduction-3/01-intro/12-json-path.md).

# JSON PATH

Query language for json

## Dictionaries

`$` is root element.

```json
{
    "car": {
        "price": "$25,000"
    }
}
```

Query price via `$.car.price`:

```json
[ "$25,000" ]
```

## Lists

```json
[
    1,
    2,
    3
]
```

Query via `$[INDEX]`:

`$[0]` is `[1]`

can do multiple: `[0,2]` is `[1,3]`

Can slice via `[START:END_EXCLUSIVE]` Can step via `[START:END_EXCLUSIVE:STEP]` Can get last via `[-1]` or `[-1:]`

## Criteria

More complex queries

```json
[
    1,
    2,
    3,
    4
]
```

`?()` for query.

`@` each item in list

So, get items `> 2`:

```
$[ $( @ > 2) ]`
```

Result: `[3,4]`

Can use `==`, `!=`, `in`, `nin`

Can check strings via `?(@.SOME_KEY == "val")`

## Wildcards

We can also use wildcards, eg all matches:

```
$[*].price
```

Or with Dictionaries:

```
$*.car
```

## JSON PATH in Kubernetes

```shell
kubectl get pods -o=jsonpath='{ .item[0].spec }'
```

`$` is added if not there.

We can combine queries for multiple results:

```shell
kubectl get pods -o=jsonpath='{ .item[0].spec }{ .items[*].metadata }'
```

We can prettify via `{ "\n" }` between queries.

We can loop with a `{range .items[*]}{ ... }{ end }`, and access internal elements inside.

Can also create custom columns via `-o=custom-columns=COL_NAME:JSON_PATH`


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.ramsdenj.com/introduction-3/01-intro/12-json-path.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
