# JSON flatten

`json-flatten` · version 1.0.0 · JSON & JSONL · free, no key needed

Flatten a JSON value into a null-prototype map keyed by RFC 6901 JSON Pointers.

**Use when you need to: json flatten · flatten json to json pointers · expand nested json into pointer keys.**

## Supported

- json flatten
- flatten json to json pointers
- expand nested json into pointer keys

## Not supported

- json pointer get
- json pointer set
- unflatten json pointers
- read files
- detect cycles

## Behavior

- value is any JSON object, array, string, boolean, null, or safe integer.
- Non-finite numbers, non-integers, and integers outside Number.MAX_SAFE_INTEGER are rejected.
- Output keys are RFC 6901 JSON Pointers; ~ is escaped as ~0 and / as ~1.
- A root scalar or empty object or array maps to the empty pointer.
- Nested empty objects and arrays are emitted as leaves at that pointer.
- Result keys are inserted in lexicographic UTF-16 order of the pointers.
- The pointers object is a null-prototype map of at most 5000 leaves; nesting depth is at most 16 from the root.

## Input

- `value` (any JSON value, required): JSON object, array, string, boolean, null, or safe integer

## Output

- `pointers` (object, required)

## Limits

- max depth: 16
- max pointers: 5000
- max output bytes: 1048576

## Example

Request input:

```json
{
  "value": {
    "a/b": 1,
    "empty": {},
    "list": [],
    "tags": [
      "a",
      "b"
    ],
    "tilde~key": false,
    "user": {
      "name": "רוני",
      "note": "line one\nline,two"
    }
  }
}
```

Response:

```json
{
  "result": {
    "pointers": {
      "/a~1b": 1,
      "/empty": {},
      "/list": [],
      "/tags/0": "a",
      "/tags/1": "b",
      "/tilde~0key": false,
      "/user/name": "רוני",
      "/user/note": "line one\nline,two"
    }
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "json-flatten",
  "version": "1.0.0",
  "input": {
    "value": {
      "a/b": 1,
      "empty": {},
      "list": [],
      "tags": [
        "a",
        "b"
      ],
      "tilde~key": false,
      "user": {
        "name": "רוני",
        "note": "line one\nline,two"
      }
    }
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/json-flatten/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"value":{"a/b":1,"empty":{},"list":[],"tags":["a","b"],"tilde~key":false,"user":{"name":"רוני","note":"line one\nline,two"}}}'
```

The machine-readable contract is at [/v1/tools/json-flatten/versions/1.0.0](/v1/tools/json-flatten/versions/1.0.0).

### CLI

```sh
node cli.mjs run json-flatten 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [JSON unflatten](/tools/json-unflatten): Reconstruct a JSON value from a map of RFC 6901 JSON Pointers to leaves.
- [JSON pointer list](/tools/json-pointer-list): List RFC 6901 pointers to every reachable JSON node, root first.
- [JSONL to array](/tools/jsonl-to-array): Parse strict JSON Lines text into an array of JSON-safe values.
- [Array to JSONL](/tools/array-to-jsonl): Serialize an array of JSON-safe values as JSON Lines text.
- [JSON array anti join](/tools/json-array-anti-join): Anti join two JSON arrays of objects on exact keys.
- [JSON array drop keys](/tools/json-array-drop-keys): Remove specific keys from each object in a JSON array.
