コンテンツへスキップ
POST AI agent ready /v1/json-extra/flatten

JSON Flatten API - Convert Nested JSON to Dot-Notation Keys

Recursively flattens an object so every leaf value sits at the top level keyed by its dotted path. Array elements get numeric indices in the path. Empty objects and arrays are preserved as-is. The delimiter defaults to "." and can be customized.

Parameters

objectrequired

Non-null, non-array object to flatten.

string

Separator between path segments.

Code examples

curl -X POST https://api.botoi.com/v1/json-extra/flatten \
  -H "Content-Type: application/json" \
  -d '{"json":{"user":{"name":"Ada","tags":["founder","engineer"]}},"delimiter":"_"}'

When to use this API

Load nested JSON into CSV or spreadsheet

CSV rows are flat; JSON is nested. Flatten each record before writing to a spreadsheet; the dotted keys become column headers. Round-trip back to JSON with /v1/json-extra/unflatten.

Key-based feature flag config

Ship deeply nested feature-flag config, flatten it at runtime, and look up values by dotted key. Works well for LaunchDarkly-style targeting rules.

Diff-friendly serialization

Flat maps diff cleanly line-by-line; nested objects produce large change sets on a single modification. Flatten before committing to version control for clearer pull-request diffs.

Frequently asked questions

How are arrays represented?
Array elements use numeric indices in the path: "tags.0", "tags.1", etc. /v1/json-extra/unflatten detects numeric keys and reconstructs the array.
What about keys that contain the delimiter?
If your JSON keys contain dots (e.g., "a.b": 1), use a different delimiter like "_" or "|". The endpoint does not escape delimiter characters in keys.
Can I pass an array at the top level?
No. The root must be a non-null, non-array object. Wrap arrays in an object (e.g., {"items": [...]}) before flattening.
How are empty objects and arrays handled?
They are preserved as leaf values at their path. Flattening {"a": {}} returns {"a": {}}, not an empty output.
Is the flattened output ordered?
Order follows the object's own key-iteration order (insertion order in modern JS). The response preserves that ordering.

Get your API key

Free tier includes 5 requests per minute with no credit card required. Upgrade for higher limits.