Blog
Wild & Free Tools

Flatten JSON to One Line: Structure Flattening vs Minifying — What You Actually Want

Last updated: January 2026 5 min read
Quick Answer

Table of Contents

  1. Definition
  2. Which do you want
  3. Tools for each
  4. Common mistakes
  5. Frequently Asked Questions

"Flatten JSON to one line" is one of the most ambiguous search queries in JSON tooling. Half the people asking want structural flattening — collapse nested objects into dot-notation keys. The other half want minifying — remove whitespace so the JSON takes up one line. These are completely different operations. This post explains the difference and helps you pick the right tool.

Two Very Different Operations

Structural flattening: Transforms the shape of the data. Nested objects become dot-notation keys.

Before: {"user": {"name": "Alice", "address": {"city": "NY"}}}

After: {"user.name": "Alice", "user.address.city": "NY"}

Minifying: Removes whitespace. Shape stays identical.

Before:

{
  "user": {
    "name": "Alice",
    "address": { "city": "NY" }
  }
}

After: {"user":{"name":"Alice","address":{"city":"NY"}}}

The minified version is still nested. The flat version is still formatted. They are independent axes — you can have flat + minified, flat + pretty, nested + minified, or nested + pretty.

Which One Do You Actually Want?

You want minifying if:

- You are embedding JSON in a URL or HTML attribute and need it compact

- You are sending JSON over a wire and want smaller payload size

- You want to paste JSON into a single cell of a spreadsheet

- You want to store JSON on a single line in a config or log file

You want structural flattening if:

- You are exporting to CSV (nested objects do not fit cells)

- You are comparing payloads in a diff and want clean line-level changes

- You are building a form where field names come from JSON paths

- You need dot-notation keys for a specific downstream tool (lodash, pandas)

If your goal involves the word "smaller" or "compact," you want minifying. If it involves the word "cell" or "column" or "flat table," you want structural flattening.

Sell Custom Apparel — We Handle Printing & Free Shipping

The Right Tool for Each

For minifying: Use our JSON Formatter. It has a Minify button that strips whitespace. The result is your original JSON on one line.

For structural flattening: Use our JSON Flattener. It collapses nesting into dot-notation keys.

Both tools run in your browser, both are free, neither uploads your data. You can chain them: flatten structure first, then minify the flat result, if you want both.

In jq on the command line:

Minify: jq -c . input.json (the -c flag stands for "compact")

Structure flatten: jq 'reduce paths(scalars) as $p ({}; .[$p | join(".")] = (getpath($p)))' input.json

The confusion between these two operations is exactly why the browser tools have clear labels. "Flatten" and "Minify" are different buttons.

Common Mistakes When People Conflate the Two

Mistake 1 — Flattening when you meant minify. Someone wants to paste JSON into a log file. They flatten it structurally and now their downstream parser cannot find user.name because the key name literally has a dot in it. They wanted minify.

Mistake 2 — Minifying when you meant flatten. Someone wants to export to CSV. They minify the JSON, paste it into Excel, and one cell contains the entire JSON blob. They wanted structural flatten.

Mistake 3 — Round-tripping through the wrong tool. Someone uses the flattener, then realizes they broke the structure, tries to reverse with "unflatten," and gets a cleaner shape — but not the original. The fix would have been to minify, which preserves structure.

If you are unsure, ask: does the downstream system need to parse nested JSON, or does it need flat keys? If parse nested → minify. If flat keys → flatten.

Pick the Right Operation

Flatten for dot-notation keys; minify for compact output. Both tools, free.

Open Free JSON Flattener

Frequently Asked Questions

What is the jq command for "flatten to one line"?

Depends on which you want. For minifying, jq -c . input.json (strips whitespace). For structural flatten, jq reduce paths(scalars) as $p ({}; .[$p | join(".")] = (getpath($p))). Use -c when you want one-line output but same structure.

How do I minify JSON in VS Code?

Install an extension like "JSON Tools" and use the minify command, or use Ctrl+A then Find/Replace with regex to strip whitespace. Our browser tool has a minify button that is faster than either.

Can I have JSON that is both flat AND minified?

Yes. Flatten structurally first to get dot-notation keys, then minify to strip whitespace. The result is one-line JSON with dot-notation keys. Useful for compact flat payloads in logs or data stores.

Does "json format without spaces" mean the same as minified?

Yes — "format without spaces," "compact JSON," "no whitespace," and "minified JSON" all describe the same operation: stripping the indentation and newlines while keeping the structure.

Marcus Webb
Marcus Webb Full-Stack Developer

Marcus leads spreadsheet and charting tool development at WildandFree, with five years of data engineering experience.

More articles by Marcus →
Launch Your Own Clothing Brand — No Inventory, No Risk