# JSON Path Editor

Get, set, or delete a value at a dotted or bracketed path in a JSON document. Supports array indices, quoted keys, and auto-created intermediates.

## Run it

- **CLI:** `gizza tool json-path-edit '{"store":{"book":[{"title":"A","price":5}]}}' 'path=store.book[0].title'`
- **Web:** https://gizza.ai/tools/json-path-edit/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/json-path-edit/tool.json

## Inputs

- `json` — JSON document _(field)_
- `path` — Path _(field)_
- `operation` — Operation _(field)_
- `value` — Value to set (for the 'set' operation) _(field)_
- `pretty` — Pretty-print the output _(field)_

## Output

- Result (text)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `json` — JSON document
- `path` — Path
- `operation` — Operation
- `value` — Value to set (for the 'set' operation)
- `pretty` — Pretty-print the output

Example: `https://gizza.ai/tools/json-path-edit/?json=%7B%22store%22%3A%7B%22book%22%3A%5B%7B%22title%22%3A%22A%22%2C%22price%22%3A5%7D%5D%7D%7D&path=store.book%5B0%5D.title&operation=get&value=9&pretty=true`

---

## About this tool

**JSON Path Editor** reads and edits a single value inside a JSON document by its
**path** — no need to hand-edit brackets and commas. Pick an operation, point at
a path, and get back either the value there (`get`) or the whole modified
document (`set` / `delete`). Everything runs locally in your browser: your JSON
is never uploaded.

Paths use the familiar **lodash / `dot-object`** style (not RFC 9535 JSONPath):

- **Dot segments** — `store.book.title`
- **Array indices** — `store.book[0]` or the equivalent dotted form `store.book.0`
- **Quoted keys** — for a key that itself contains a dot, bracket, or space, quote
  it inside brackets: `["first name"]` or `["a.b"].c`
- An optional leading `$` is accepted and ignored (`$.store.book[0]`), and an
  **empty path** selects the whole document.

### Worked example

Given this document:

```json
{"store":{"book":[{"title":"A","price":5},{"title":"B","price":12}]}}
```

- **get** `store.book[1].title` → `"B"`
- **set** `store.book[0].price` to `9` → `{"store":{"book":[{"title":"A","price":9},{"title":"B","price":12}]}}`
- **delete** `store.book[0]` → `{"store":{"book":[{"title":"B","price":12}]}}` (the array shifts down)

### Setting values

For `set`, the **value** field is parsed as JSON: `42` becomes a number, `true` a
boolean, `null` a null, and `{"k":1}` an object. If it isn't valid JSON it's
stored as a plain string, so a bare `hello` becomes `"hello"`. To force text that
looks like JSON to stay a string, wrap it in quotes — e.g. `"true"` sets the
string `true`, not the boolean.

`set` **creates missing intermediates**: setting `user.address.city` on `{}`
builds the nested objects for you, and a numeric segment such as `list[2]` creates
an array (padding earlier slots with `null`).

### Limits & edge cases

- **`get`** errors if the key or array index doesn't exist (rather than returning
  nothing), so a typo is obvious. **`delete`** likewise errors if there's nothing
  at the path.
- **`set` won't clobber a scalar**: trying to set `a.b` when `a` is already a
  string or number errors instead of silently overwriting your data.
- Array growth on `set` is capped at 100,000 elements, so a typo like
  `a[999999999]` errors instead of allocating a huge array.
- Object key order is preserved on `set`/`delete`.

## FAQ

<details>
<summary>What path syntax does this use — is it JSONPath?</summary>

No. It uses **lodash / `dot-object`** notation: dot segments (`a.b.c`), array
indices as brackets or dotted digits (`a[0]` is the same as `a.0`), and quoted
keys for keys containing a dot, bracket, or space (`["a.b"].c`). This targets one
value at a time. For RFC 9535 JSONPath queries with wildcards, slices, recursive
descent, and filters, use a dedicated JSONPath query tool instead.

</details>

<details>
<summary>How do I set a value that looks like JSON but should stay a string?</summary>

Wrap it in quotes. The **value** field is parsed as JSON first, so `true`, `42`,
and `null` become a boolean, number, and null. Typing `"true"` (with the quotes)
stores the string `true`. A bare word that isn't valid JSON,
like `hello`, is already treated as the string `"hello"`.

</details>

<details>
<summary>Will `set` create missing objects and arrays along the path?</summary>

Yes. Setting `user.address.city` on `{}` creates the `user` and `address` objects
automatically. A numeric segment creates an array — `items[2]` builds a
three-element array padded with `null`. What it will **not** do is overwrite an
existing scalar: if `a` is already `5`, setting `a.b` errors instead of destroying
the `5`.

</details>

<details>
<summary>What happens if the path doesn't exist?</summary>

For **get** and **delete**, a missing key or an out-of-range array index is an
error with a message that says which segment failed — so a typo surfaces
immediately rather than silently doing nothing. For **set**, a missing path is the
normal case: it's created.

</details>

<details>
<summary>Is my JSON uploaded anywhere?</summary>

No. The whole tool runs as WebAssembly inside your browser tab. Your JSON document
never leaves your device, so it's safe to use with private or sensitive data.

</details>

## Related tools

- [Query String Parser](https://gizza.ai/tools/parse-query-string/): Parse a URL query string into key/value pairs and structured JSON — repeated keys, PHP/Rails bracket notation, percent and + decoding. Free, in your browser.
- [Adjacency Matrix Converter](https://gizza.ai/tools/adjacency-matrix-converter/): Convert a graph between edge list, adjacency matrix, and incidence matrix — directed or undirected, weighted or not. Free, private, runs in your browser.
- [Amazon Order Analyzer](https://gizza.ai/tools/amazon-order-analyzer/): Paste an Amazon order-history CSV export to summarize total spend by month, top items, and category breakdowns. Browser-only, private, with Markdown or JSON output.
- [Avro to JSON Converter](https://gizza.ai/tools/avro-to-json/): Decode Apache Avro Object Container Files (.avro / OCF) to JSON, NDJSON, or the embedded schema — no .avsc needed, free and private in your browser.
- [Reconcile bank statement and ledger CSVs](https://gizza.ai/tools/bank-statement-reconcile/): Match bank-statement CSV rows to ledger rows by date, signed amount, and fuzzy memo similarity, with unmatched and suggested matches.
