Flatten API Response JSON
Flatten REST, GraphQL, and webhook responses into readable path keys so contract drift, missing fields, and nested values are easier to compare.
Paste your JSON → Get results instantly (no signup)
→ Flatten or nest keys in this JSON structure and flatten nested object.
1{2 "user.name": "Alice",3 "user.address.city": "NYC",4 "user.address.zip": "10001"5}Love the result?
Use this exact pipeline in your app, backend, or LLM workflow.
No setup needed. Works with curl, Node, Python.
Uses example data. For edited input, copy from the playground.
Works with:
- REST API responses
- GraphQL payloads
- Webhook bodies
- Vendor SDK output
Example: input → output
Flatten API response JSON
API responses are optimized for applications, not for human inspection. A REST endpoint can return customer identity, billing state, feature flags, permissions, and nested metadata in one payload. A webhook can bury the important value several objects deep. Flattening the API response turns those hidden values into path keys that are easier to search, compare, export, and discuss.
This page uses the same engine as the Flatten JSON tool, but the examples focus on REST responses, GraphQL results, webhook payloads, and vendor SDK output.
REST API response example
Input:
{
"data": {
"id": "cus_123",
"attributes": {
"email": "ada@example.com",
"billing": {
"status": "active",
"currency": "USD"
}
}
},
"meta": {
"request_id": "req_789"
}
}Flattened output:
{
"data.id": "cus_123",
"data.attributes.email": "ada@example.com",
"data.attributes.billing.status": "active",
"data.attributes.billing.currency": "USD",
"meta.request_id": "req_789"
}That path map is much easier to paste into a ticket, compare against another environment, or convert into a CSV row.
API debugging use cases
- Compare sandbox and production responses with JSON Diff.
- Check whether a webhook includes the fields your handler expects.
- Give QA a readable field list without sending a giant nested document.
- Flatten vendor SDK output before cleaning noisy fields with Clean JSON.
- Prepare sample responses for docs, tests, and import scripts.
Flatten GraphQL and webhook payloads
GraphQL results often repeat nested edges, nodes, and fragments. Webhooks often wrap the useful object inside event metadata. Flattening can expose the actual fields that changed, but arrays still need careful handling. For event batches and repeated child records, use Flatten JSON Array.
API response flattening vs schema validation
Flattening makes a payload easier to inspect. Schema validation proves that the payload matches a contract. They work well together: flatten first when you need a readable report, validate when code depends on required fields and types.
For strict contracts, run JSON Schema Validator after inspecting the shape. For CSV exports, use Flatten JSON for CSV after you confirm the response contains the data you expect.
When to keep API JSON nested
Keep the original nested response as the canonical version for app code. Flattened JSON is best at boundaries: reporting, debugging, comparison, docs, and spreadsheet handoff. If you need to send a request body back to an API, rebuild the nested object with Unflatten JSON or return to the main JSON flattener and switch direction.
Related flatten JSON tools
- JSON flattener - flatten or nest arbitrary JSON online.
- Flatten JSON Array - handle event batches, search results, and repeated records.
- Flatten JSON for CSV - export API responses to CSV, Excel, and BI tools.
- Flatten JSON in JavaScript - compare API payload path maps with JS helpers.
- Unflatten JSON - rebuild API-ready request bodies from flat keys.
Frequently asked questions
Why flatten an API response?+−
Flattening exposes nested values as readable paths, which makes responses easier to debug, compare, export, and discuss in tickets or QA reports.
Does this work with webhook payloads?+−
Yes. Webhooks are often deeply nested, and flattening can reveal event data, object fields, metadata, and request identifiers in one path-level view.
Should production code consume flattened API JSON?+−
Usually no. Keep nested JSON as the canonical API shape. Flatten at the boundary for debugging, reporting, comparison, or spreadsheet export.
Related tools
- Rename KeysRename known keys or convert key casing without changing the underlying values
- Find & ReplaceFind and replace matching keys or values across JSON using broad search patterns
- FilterFilter rows, items, keys, or values by explicit conditions and keep only the matches you want
- Pick FieldsKeep only a known allowlist of fields and remove everything else
- RestructureFlexibly restructure collections by grouping, unwinding, transposing, or rearranging nested data
Read more on the blog
Advanced usage (optional)
Flatten / Nest
v1.0.0Description
Flatten / Nest
Convert between nested and flat object structures. Flatten deep objects into single-level key-value pairs, or nest flat keys back into hierarchical objects. Supports multiple key formats: delimiter-separated, camelCase, snake_case, PascalCase, and kebab-case.
Modes
Flatten
Convert nested objects into flat keys. Each nested path becomes part of the key name.
{ "user": { "name": "Alice" } } → { "user.name": "Alice" }Nest
Convert flat keys back into nested objects by splitting on the delimiter or case boundaries.
{ "user.name": "Alice" } → { "user": { "name": "Alice" } }Key Formats
Delimiter (default)
Join/split key segments with a character (default: .).
- Flatten:
user+name→user.name - Nest:
user.name→user/name
camelCase
Join/split on uppercase letter boundaries.
- Flatten:
user+address+city→userAddressCity - Nest:
userAddressCity→user/address/city
snake_case
Join/split on underscores.
- Flatten:
user+address+city→user_address_city - Nest:
user_address_city→user/address/city
PascalCase
Same as camelCase but with uppercase first letter.
- Flatten:
user+name→UserName
kebab-case
Join/split on hyphens.
- Flatten:
user+name→user-name
Configuration
| Field | Type | Default | Description |
|---|---|---|---|
| Mode | enum | flatten | flatten or nest |
| Key Format | enum | delimiter | delimiter, camelCase, snake_case, PascalCase, or kebab-case |
| Delimiter | string | . | Character(s) used to join/split key segments (only for delimiter format) |
| Max Depth | number | 0 | Maximum nesting depth to flatten (0 = unlimited) |
| Target Paths | path-picker | [] | Scope operation to specific paths only (empty = apply everywhere) |
Use Cases
API Integration
- Flatten for forms: Convert nested API responses to flat form field names
- Nest for APIs: Convert flat form data back to nested API request bodies
- Format conversion: Transform between dot-notation and camelCase conventions
Database Operations
- MongoDB flattening: Flatten nested documents for tabular export
- SQL mapping: Convert hierarchical JSON to flat column names for SQL insertion
- Schema migration: Convert between naming conventions (snake_case ↔ camelCase)
Configuration Management
- Environment variables: Flatten config objects to dot-notation for
.envfiles - Depth limiting: Flatten only the first level while preserving deep structures
Configuration
| Name | Type | Default | Description |
|---|---|---|---|
| Mode | enum | flatten | flatten: convert nested objects to flat keys. nest: convert flat keys back to nested objects. flatten nest |
| Key Format | enum | delimiter | delimiter: use a character to join/split. Others: camelCase, snake_case, PascalCase, kebab-case. delimiter camelCase snake_case PascalCase kebab-case |
| Delimiter | string | . | Character(s) used to join/split key segments (default is dot) |
| Max Depth | number | 0 | Maximum nesting depth to flatten (0 = unlimited) |
| Target Paths | path-picker | [] | Scope operation to specific paths only (empty = apply everywhere) |
Examples
Flatten or nest keys in this JSON structure and flatten nested object.1{2 "user.name": "Alice",3 "user.address.city": "NYC",4 "user.address.zip": "10001"5}API Usage
curl -X POST https://your-domain.com/api/v1/utilities/structure.flatten-nest \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"inputs":{"primary":{"user":{"name":"Alice","address":{"city":"NYC","zip":"10001"}}}},"config":{"mode":"flatten","delimiter":".","maxDepth":0,"targetPaths":[]}}'1{2 "user.name": "Alice",3 "user.address.city": "NYC",4 "user.address.zip": "10001"5}