I have a JSON which has entries that look like
[{ "key": { "keyLabel": "Label1" }, "specs": [{ "specKey": "spec1", "specValue": ["s11"] }, { "specKey": "spec2", "specValue": ["s12"] }] },
{ "key": { "keyLabel": "Label2" }, "specs": [{ "specKey": "spec1", "specValue": ["s21"] }, { "specKey": "spec3", "specValue": ["s22"] }] }]
Spec Keys present changes on the basis of KeyLabel value. As you can see above if if KeyLabel = Label1, spec1 and spec2 are present. If KeyLabel = Label2, spec1 and spec3 are present
I want to create a CSV/Excel using this such that header/top row as following columns
KeyLabel, spec1, spec2, spec3 (basically union of all specKeys)
Label1, s11,s12
Label2, s21, ,s22
So, the challenging part is that at the time of writing to file, I need to write under in the appropriate column.
Any thoughts on if there are any csv/excel libraries which make this easier. Naive way does seem very elegant - which is to store the ordered list of headers and basic on key write commas and values so that values are in write column
Label2, s21, ,s22