Snipget.ai

Flatten nested JSON to dotted keys

Exact
json_flatten

Deterministic and authoritative — the canonical answer for this input.

Flatten a nested JSON object/array into a single-level map of dotted paths to leaf values ({'a': {'b': 1}} → {'a.b': 1}; array items use their index, e.g. users.0.email). Processing multiple inputs? Use `json_flatten_batch` to do up to 1000 in one call.

Parameters

valuestringrequired

The nested JSON to flatten.

separatorstringoptional

Path separator joining nested keys.

Call it

curl -X POST https://api.snipget.ai/v1/json/flatten \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{"value":"{\"user\": {\"name\": \"Ada\", \"address\": {\"city\": \"London\"}}}"}'

The Batch tab sends up to 1000 inputs in one call via /v1/json/flatten/batch.

Example response

{
  "input": "{\"user\": {\"name\": \"Ada\", \"address\": {\"city\": \"London\"}}}",
  "is_valid": true,
  "flattened": {
    "user.name": "Ada",
    "user.address.city": "London"
  },
  "key_count": 2,
  "separator": "."
}

FAQ

Why flatten JSON?

Nested JSON is hard to scan, compare, or drop into a spreadsheet. Flattening turns it into one flat list of dotted paths and their values, so user.address.city sits right next to its value. The result is exact and repeatable.

What happens to lists?

List items get their position number as a path segment, so the first email under users becomes users.0.email. This keeps every leaf addressable by a single key.

Can I change the separator?

Yes. The default joiner is a dot, but you can set separator to something else, for example a slash, if your keys already contain dots.

Can I get the nested version back?

Yes. Unflatten is the exact inverse. It rebuilds the original nested structure from the flat dotted-path map.

What if the input is not valid JSON?

You get confidence 0 and a short reason explaining the JSON was invalid, not an error. Nothing is flattened until the input parses.

Related tools