巢狀 JSON 的注意事項
- 貼上
- 確認
JSON from APIs and the like often has a "nested" form, where data contains further data. Here are cautions for converting nested JSON to CSV with Convert CSV and JSON.
步驟
- For "Direction", choose "JSON → CSV".
- Paste the JSON into "Before conversion".
- Press "Convert".
- Check "After conversion".
What nesting is
For example, data like this.
- Name: Yamada
- Address: (prefecture: Tokyo, city: Shinjuku)
Inside "Address" are further items. That is nesting.
The result after conversion
CSV is a flat table. Nested parts cannot take a table form, so their content goes into a single cell as text.
Ways to flatten
- Expand the items: bring the contents of the address out as separate items "prefecture" and "city".
- Fix with a text editor: change the structure with find-and-replace and so on.
- Extract just the needed parts: make JSON with only the target items.
How much to fix
- The values inside the nesting aren't needed → fine as it is
- You want to total the values inside the nesting in Excel → flatten before converting
Nested arrays (lists)
When one item holds several values (a list), it also goes into one cell as text. If you want rows split per list element, reshape first.
適合
- Converting simply structured JSON (no nesting)
- When it is enough to see the nested contents as they are
示例
Converted order data JSON. The "products" item held a list of products and went into one cell as text. To total per product, reshaped it to one row per product first and converted again.
Common stumbling blocks
- A cell is full of brackets and symbols: that is the nested part.
- The number of columns differs by row: data with uneven items.
Frequently asked questions
Can nesting be expanded automatically?
This tool does not expand nesting. Reshape first.
小結
Nesting goes into one cell as text. If you want to total it, flatten first.
使用「CSV 與 JSON 互相轉換」(免費)搭配使用的工具
- 刪除重複行並排序:刪除重複的行並排序。
- 把檔案打包成 ZIP:把多個檔案打包成一個 ZIP。
- 文字數統計(用於求職申請表和報告):統計文字的字數、行數和稿紙張數。