1001Ferramentas
🪜 Dev

JSON Flatten / Unflatten

Flatten a nested JSON into dot-notation keys (e.g. user.address.city) and rebuild the reverse path. Useful to export to CSV, generate .env files or compare configs. Everything in your browser.

Quando usar?

Achatar JSON (flatten) transforma estruturas aninhadas em um único nível com chaves em notação de ponto. Útil para exportar para CSV/planilhas, gerar arquivos .env, comparar configurações, ou enviar campos a APIs que esperam pares chave/valor planos.

Reconstruir (unflatten) faz o caminho inverso. Use em scripts de migração, ao mesclar dados de planilhas em estruturas, ou para transformar variáveis de ambiente em config aninhada. Tudo no navegador — nada é enviado a servidores.

From nested JSON to flat keys and back

Sometimes you need a deeply nested JSON as plain key/value pairs: to drop it into a spreadsheet, build a .env file, diff two configs, or feed a system that only takes flat fields. Flattening by hand is tedious and easy to get wrong. Paste your JSON here and it turns into dot-notation keys (user.address.city) as you type. The Unflatten mode does the reverse trip, rebuilding the nested structure from the flat keys.

Two details matter in practice. Array items can come out in bracket notation (tags[0]) or as an index joined by the separator (tags.0) — brackets are what the rebuild step uses to tell an array apart from an object with a key named 0. Empty arrays and objects are kept as [] and {} instead of silently disappearing. And when rebuilding, keys like __proto__, constructor and prototype are rejected on purpose: they are the classic prototype pollution vector in JavaScript.

If any of your keys already contains a dot, change the separator (the field takes up to 3 characters, __ works well) before flattening, or the rebuild will split that key into two levels. A quick sanity check: flatten, paste the result into Unflatten mode and confirm you get the original back. Everything runs in your browser — the JSON never leaves your machine, so internal configs are fine to paste here.

Frequently asked questions

What happens to empty arrays and objects?
They are preserved as [] and {}. Without that, a flatten and unflatten round trip would lose information.
Can I use a separator other than a dot?
Yes, the separator field takes up to 3 characters. Handy when your keys already contain dots, like domain names or version numbers.
Why do I get an error about __proto__?
The rebuild step refuses __proto__, constructor and prototype keys on purpose, to prevent prototype pollution attacks.

Related Tools