# JSON Structure Surgery

Operate on JSON structure with a record of every cut — inventory the key paths before touching anything, address nodes precisely with RFC 6901 pointers or flexibly with JSONPath, rename keys by rule instead of by hand, apply RFC 6902 patches as an auditable operation sequence, and flatten to travel with a lossless way back.

> Canonical page: https://elysiatools.com/en/hubs/json-structure-surgery

- **Keywords:** flatten nested JSON, unflatten JSON, rename JSON keys, JSON Patch RFC 6902, JSON Pointer RFC 6901, JSONPath query, extract JSON keys, restructure JSON

## Frequently asked questions

### Is flatten-then-unflatten really lossless?

It is, when the delimiter cannot occur inside a key — that is why the collision check comes first. Dots inside key names, arrays of arrays, and empty objects are the classic casualties when the check is skipped; with the right separator and a deliberate test of the ugly cases, the deep comparison after the round trip is the proof.

### What does a patch buy over just editing the file?

A trail. The patch is a list of named operations — add, remove, replace, move — each targeting a pointer, which means it can be read before it runs, reviewed as a diff, replayed against the same input, and archived as the record of what was done and why. An edit has a result; a patch has a result and a story.

### When do I use the pointer tool instead of the path tool?

The pointer is a scalpel address — one exact node, and the dialect the patch format itself speaks, so pointer fluency is a prerequisite for patches. The path query is a search — wildcards, filters, sets of nodes — for exploring what exists before deciding what to operate on. Explore with paths, operate with pointers.

### Why extract the key inventory at all?

Because structure drift is invisible from the outside. Two API responses that look alike can differ by one nested key, and a rename rule written against yesterday's shape misses today's. The inventory costs seconds, exposes every path including the surprising ones, and becomes the baseline that proves later operations changed only what they claimed.

## Related content

- [JSON Field Extraction, Transformation, and Provenance](https://elysiatools.com/en/hubs/json-extraction-transformation-and-provenance): Extract selected JSON fields by path, reshape the payload with JSONata, and record field-level provenance without claiming business-semantic validation.
- [JSON Utility, Inspection, and Transformation Tools](https://elysiatools.com/en/hubs/json-utility): Format, inspect, compare, merge, transform, validate, analyze, and watermark JSON payloads for API and data workflows.
- [JSON Normalization and Interchange Workflow](https://elysiatools.com/en/hubs/json-convert): Turn a structured source into a checked JSON representation, then export the exact table, configuration, document, API, XML, CSON, EDN, BSON, or UBJSON form required downstream.
- [JSON to Typed Code Generators](https://elysiatools.com/en/hubs/json-to-typed-code-generators): Generate typed models from JSON or schema evidence for TypeScript, Go, Rust, Kotlin, Java, C#, and Zod validation workflows.
- [Infer JSON Schema from Samples and Spreadsheets](https://elysiatools.com/en/hubs/json-schema-inference-from-samples-and-spreadsheets): Derive a reviewable JSON Schema draft from representative JSON samples or XLSX rows, then inspect types, requiredness, nulls, and outliers before treating it as a contract.
