⇲

JSON Flattener

Convert nested JSON into flat key-value paths

JSON Flattener — what it does

Convert nested JSON into a flat set of key-value pairs, where each key is the full dot path to its value and the separator is yours to choose. Flattening is what makes deep JSON fit into things that have no concept of nesting: spreadsheets, CSV files, environment variables and log fields.

When this tool helps

  • Preparing a nested API response for import into a spreadsheet or CSV.
  • Turning a nested configuration file into flat environment-variable-style keys.
  • Getting a readable overview of an unfamiliar payload's full structure at a glance.

How to use it

  1. Paste the JSON document.
  2. Set the key separator, typically a dot.
  3. Flatten the JSON.
  4. Copy the flattened key-value pairs.

Accuracy, limits, and good practice

  • Array elements become indexed keys such as items.0.name, which is exactly what you need for a CSV column header.
  • Choose a separator that does not occur in your key names, or the flattened paths become ambiguous to anything reading them back.
  • Flattening is a one-way trip in practice — rebuilding the nesting requires knowing which segments were arrays and which were objects.

Frequently asked questions

Why flatten at all?

Because tables and CSV have no nesting. Flat paths are the standard way to represent hierarchy in a column header.

What happens to empty objects and arrays?

They have no leaf values, so they contribute no rows; only paths that end in a scalar value appear.

Can I go the other way?

Not with this tool. Reconstructing nesting from paths needs a parser that knows the intended shape.

Related tools on this site

Everything above runs inside this page. JSON Flattener needs no account, no upload, and no server round trip — close the tab and nothing is left behind.

JSON 扁平化能做什麼

把巢狀 JSON 轉成扁平的鍵值組,每個鍵都是通往該值的完整點路徑,分隔符由你決定。攤平能讓深層 JSON 塞進沒有巢狀概念的東西裡:試算表、CSV、環境變數與日誌欄位。

什麼時候用得上

  • 把巢狀 API 回應整理成可匯入試算表或 CSV 的形式。
  • 把巢狀設定檔轉成環境變數風格的扁平鍵名。
  • 一眼掌握陌生載荷的完整結構。

使用步驟

  1. 貼上 JSON 文件。
  2. 設定鍵名分隔符,通常用點。
  3. 執行攤平。
  4. 複製攤平後的鍵值組。

精確度、限制與實務建議

  • 陣列元素會變成帶索引的鍵,例如 items.0.name,正好可以當 CSV 的欄位標題。
  • 分隔符請挑不會出現在鍵名中的字元,否則攤平後的路徑對讀取端會產生歧義。
  • 實務上攤平是單向的——要還原巢狀,必須知道哪些層級原本是陣列、哪些是物件。

常見問題

為什麼要攤平?

因為表格與 CSV 沒有巢狀。用扁平路徑當欄位標題,是表達階層的標準做法。

空物件與空陣列會怎樣?

它們沒有葉節點值,因此不會產生任何項目;只有以純量值結尾的路徑會出現。

可以反向還原嗎?

本工具不行。從路徑重建巢狀,需要知道原本預期結構的解析器。

本站相關工具

以上步驟全部在這個頁面內完成,JSON 扁平化 不需要註冊、不上傳檔案、也不經過伺服器,關閉分頁後不會留下任何資料。