# JSON operations

## Format, validate, and minify

- Call `POST /v1/json/format` with `input` and optional integer `indent` from 0 through 8. `input` may be JSON text or a parsed JSON value. Read `data.result` and `data.indent`.
- Call `POST /v1/json/validate` with JSON text in `input`. Invalid JSON is a completed validation result, so HTTP 200 can contain `data.valid: false`. Never describe that input as valid.
- Call `POST /v1/json/minify` with JSON text in `input`. Read compact JSON from `data.result`.

```json
{"input":"{\"name\":\"11DZ\"}","indent":2}
```

Parse format and minify output once as a consistency check when practical. Formatting and minification allow at most 128 nested levels and a 1 MiB serialized-output budget.

## Sort object keys

Call `POST /v1/json/sort` with `input`, optional `direction: "asc" | "desc"`, and optional `indent` from 0 through 8.

```json
{"input":{"z":1,"a":{"b":2,"a":1}},"direction":"asc","indent":2}
```

The operation recursively sorts object keys by Unicode code point and preserves array order. It accepts at most 128 nested levels and 100,000 JSON nodes, and its serialized result is capped at 1 MiB. Read `data.result`, `data.direction`, and `data.indent`.

## Structural diff

Call `POST /v1/json/diff` with `left` and `right` JSON values.

```json
{"left":{"a":1},"right":{"a":2,"b":true}}
```

Read `data.equal` and deterministic `data.changes`. Each change uses `add`, `remove`, or `replace` and an RFC 6901 JSON Pointer. An empty path addresses the root. Each of `left` and `right` accepts at most 128 nested levels and 100,000 JSON nodes. The operation returns at most 5,000 changes and caps the serialized changes at 1 MiB.

## Escape and unescape string content

- Call `POST /v1/json/escape` with string `input` to produce strict JSON string content without surrounding quotes.
- Call `POST /v1/json/unescape` with escaped string content in `input` to decode it strictly.

Both operations reject unpaired Unicode surrogates. Do not silently repair invalid escapes.

## Bounded failures

The 100,000-node traversal limit applies to key sorting and separately to each structural-diff input; it does not describe validate, format, minify, escape, or unescape. Formatting and minification use their documented 128-level and 1 MiB serialization budgets. Escape and unescape cap their string result at 1 MiB. Report stable JSON or input-limit error codes; do not retry the same oversized or malformed input.
