JSON Flattener
Work with JSON data more effectively using this json flattener. Validate, format, and manipulate JSON with ease.
Features
- Syntax Validation: Catch JSON errors instantly
- Pretty Printing: Format JSON for readability
- Minification: Compress JSON for production
- Path Navigation: Find and extract specific values
Example
Input:
``
{"user": {"name": "John", "address": {"city": "NYC"}}}
`
Output:
`
{"user.name": "John", "user.address.city": "NYC"}
`
Tips
Uses dot notation for paths- Arrays use index notation [0]
- Useful for database imports
How to Use
1. Paste your JSON in the input area
2. Click process to validate and format
3. Review the results
4. Copy or download the result
Best Practices
- Always validate JSON before using in production
- Use consistent indentation (2 or 4 spaces)
- Keep keys in a consistent order
- Remove unnecessary whitespace for APIs
Flattening Nested JSON
Flattening turns nested structure into dotted paths, which is what you need for CSV export,
form field names, feature flags and analytics events.
`javascript
{ user: { name: "Ada", tags: ["a", "b"] } }
// becomes
{ "user.name": "Ada", "user.tags.0": "a", "user.tags.1": "b" }
`
Three decisions have to be made and there is no universal right answer:
Array notation.tags.0ortags[0]? The bracket form round-trips more reliably.Empty objects and arrays. Do they disappear, or become{}? Disappearing loses
information.
Keys containing dots.{"a.b": 1}flattens to the same path as{"a": {"b": 1}},
and cannot be unflattened unambiguously.If the data will be unflattened later, escape separators in keys or use a different one.
Numbers Are the Recurring Problem
A JSON number is an IEEE 754 double. Three consequences that bite in production:
id_str
Twitter hit the first one publicly: 64-bit tweet IDs arrived in JavaScript rounded, so the
API began sending an Value What happens Integers above 2⁵³ Silently lose precision — send IDs as strings Money as a float 0.1 + 0.2 = 0.30000000000000004 Leading zeros 007 is invalid JSON; "007" is a stringNaN and InfinityNot valid JSON at all alongside every id.
Keys, Order and Duplicates
Objects are formally unordered, though every JavaScript engine preserves insertion order for
string keys — with one exception: integer-like keys sort numerically and come first.
`javascript
JSON.stringify({ b: 1, 2: 2, a: 3 }); // {"2":2,"b":1,"a":3}
`
Duplicate keys are not an error in the spec, and JSON.parse keeps the last one. Two
parsers can legitimately disagree about which value wins, which has been the basis of real
request-smuggling attacks.
Before and After
`json
{"user":{"name":"Ada","tags":["x","y"]}}
`
becomes
`json
{
"user.name": "Ada",
"user.tags[0]": "x",
"user.tags[1]": "y"
}
`
Flattening is lossy for empty objects and for keys that already contain the separator — {"a.b": 1} and {"a": {"b": 1}} flatten identically.
Rules That Prevent Most JSON Bugs
| Rule | Why |
|---|---|
| No trailing commas | {"a": 1,} is invalid JSON, though JavaScript accepts it in object literals |
| Double quotes only | {'a': 1} is not JSON |
| Keys must be quoted | {a: 1} is a JavaScript object, not JSON |
| No comments | There is no comment syntax; JSON5 and JSONC are different formats |
No undefined, NaN, Infinity | JSON.stringify silently drops or nulls them |
| Numbers are IEEE 754 doubles | Integers above 2⁵³ lose precision — send them as strings |
Parsing Safely
`javascript
try {
const data = JSON.parse(text);
} catch (error) {
// The message names the character offset, which is the fastest way
// to find an unescaped quote in a large document.
console.error(error.message);
}
`
JSON.parse` throws on invalid input rather than returning null, so it always belongs in a try/catch when the source is a file, a request body or a clipboard paste.