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:
{
"value": {
"a/b": 1,
"empty": {},
"list": [],
"tags": [
"a",
"b"
],
"tilde~key": false,
"user": {
"name": "רוני",
"note": "line one\nline,two"
}
}
}
Response:
{
"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), then call execute with:
{
"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)
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.
CLI
node cli.mjs run json-flatten 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- JSON unflatten: Reconstruct a JSON value from a map of RFC 6901 JSON Pointers to leaves.
- JSON pointer list: List RFC 6901 pointers to every reachable JSON node, root first.
- JSONL to array: Parse strict JSON Lines text into an array of JSON-safe values.
- Array to JSONL: Serialize an array of JSON-safe values as JSON Lines text.
- JSON array anti join: Anti join two JSON arrays of objects on exact keys.
- JSON array drop keys: Remove specific keys from each object in a JSON array.