My orders JSON has a different number of items in each order. Should I flatten them into columns or keep them in one cell?
It depends on what you will do with the file. Flattening writes items by position, so the order with the most items decides how many item columns every row gets, and shorter orders leave those cells empty. If you want one row per order, or plan to rebuild the structure later, choose 'JSON text in one cell'.
What happens to the columns when you flatten
Take two orders: the first has one item, the second has three. Each item is an object with a field t. As JSON:
[{"id":1,"items":[{"t":"a"}]},{"id":2,"items":[{"t":"a"},{"t":"b"},{"t":"c"}]}]
With the default 'Flatten with dot names like a.b', the tool produced four columns:
id,items.0.t,items.1.t,items.2.t
1,a,,
2,a,b,c
The column items.0.t means 'field t of the first item', and items.2.t means 'of the third item'. The first order has no second or third item, so those two cells stay empty. If each item carried five fields instead of one, and the longest order held ten items, you would get fifty item columns on their own.
And with 'JSON text in one cell'?
The same two orders gave only two columns:
id,items
1,"[{""t"":""a""}]"
2,"[{""t"":""a""},{""t"":""b""},{""t"":""c""}]"
Each item list stays whole in one cell as JSON text. The doubled quotes are how CSV stores quotes inside a cell, and they disappear when the file is read.
Which one to choose
- Flatten when orders hold a similar, small number of items and you want to see each item in its own cell in Excel.
- Choose 'JSON text in one cell' when orders vary a lot, when you want a report with one row per order, or when a developer needs the full structure.
- If you want one row per item, repeating the order number on each, neither option does that. Prepare the JSON in that shape at the source: an array with one object per item, each carrying its order number.
Steps
- Open the CSV and JSON converter and choose 'JSON to CSV'.
- Paste the order data. If it is long, check its structure first in the JSON formatter and validator.
- Under 'Nested values', pick the method that suits you.
- Read the summary: row and column counts, and how many nested values were handled.
- Download the file.
A note on missing fields
In the example, the first order's cells stayed empty because the second and third items do not exist at all. CSV cannot tell an empty cell for a missing value from an empty cell for null. If that difference matters to whoever uses the file, the one-cell option is safer because it keeps the list exactly as it was.
Common questions
Are extra items in long orders dropped?
No. Flattening adds as many columns as the longest order needs, so no item is lost.
Is the column order fixed?
Columns appear in the order each field is first seen in the data.
Can I turn the one-cell file back into JSON?
Yes. Converting it with 'CSV to JSON' returns the cell as text, which a developer can parse as JSON again.
