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)

⚡ Instant resultsNo signupRuns in your browser
Try examples:

Flatten or nest keys in this JSON structure and flatten nested object.

{
"user": {
"name": "Alice",
"address": {
"city": "NYC",
"zip": "10001"
}
}
}
Output
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.

Read integration guide

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.

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

Read more on the blog

Advanced usage (optional)

Flatten / Nest

v1.0.0
Structure
objectarrayreversible

Description

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 + nameuser.name
  • Nest: user.nameuser / name

camelCase

Join/split on uppercase letter boundaries.

  • Flatten: user + address + cityuserAddressCity
  • Nest: userAddressCityuser / address / city

snake_case

Join/split on underscores.

  • Flatten: user + address + cityuser_address_city
  • Nest: user_address_cityuser / address / city

PascalCase

Same as camelCase but with uppercase first letter.

  • Flatten: user + nameUserName

kebab-case

Join/split on hyphens.

  • Flatten: user + nameuser-name

Configuration

FieldTypeDefaultDescription
Modeenumflattenflatten or nest
Key Formatenumdelimiterdelimiter, camelCase, snake_case, PascalCase, or kebab-case
Delimiterstring.Character(s) used to join/split key segments (only for delimiter format)
Max Depthnumber0Maximum nesting depth to flatten (0 = unlimited)
Target Pathspath-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 .env files
  • Depth limiting: Flatten only the first level while preserving deep structures

Configuration

NameTypeDefaultDescription
Modeenumflattenflatten: convert nested objects to flat keys. nest: convert flat keys back to nested objects. flatten nest
Key Formatenumdelimiterdelimiter: use a character to join/split. Others: camelCase, snake_case, PascalCase, kebab-case. delimiter camelCase snake_case PascalCase kebab-case
Delimiterstring.Character(s) used to join/split key segments (default is dot)
Max Depthnumber0Maximum nesting depth to flatten (0 = unlimited)
Target Pathspath-picker[]Scope operation to specific paths only (empty = apply everywhere)

Examples

AI Prompt
Flatten or nest keys in this JSON structure and flatten nested object.
{
"user": {
"name": "Alice",
"address": {
"city": "NYC",
"zip": "10001"
}
}
}
Output
1{
2 "user.name": "Alice",
3 "user.address.city": "NYC",
4 "user.address.zip": "10001"
5}
Config
Mode
flatten
Delimiter
.
Max Depth
0
Target Paths
all

API Usage

POST /api/v1/utilities/structure.flatten-nest
Example:
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":[]}}'
Response
1{
2 "user.name": "Alice",
3 "user.address.city": "NYC",
4 "user.address.zip": "10001"
5}