How to Convert Nested JSON to CSV
A nested JSON export may contain objects and arrays inside each record. A CSV has a fixed set of columns, so decide what one row represents and how each column gets its value before asking GRACE to convert the file.
Map JSON fields to CSV columns
Choose the record level first. For a shipment manifest, use one row per shipment. Map nested fields explicitly, such as destination.city to city and shipping.carrier to carrier. Include an ordered list of output columns.
State which fields can be blank and what goes in the cell when they are missing. Preserve shipment IDs as text. CSV readers can infer types when opening a file, so configure the receiving tool to import ID columns as text too.
shipment_id ← shipment_id
city ← destination.city
carrier ← shipping.carrier
last_status ← status of the event with the latest timestampChoose what to do with arrays
For a summary, choose one value from the array by a rule such as the latest timestamp. A transaction history may need one row per event instead. Keep the parent ID on every event row so the results can be joined back to the manifest.
Arrays may arrive out of order. The sample shipment’s delivered event appears before packed in the file, yet delivered has the later timestamp. The shipment with no events should have an empty last_status cell.
Verify the CSV with the tool that will import it
Check the header order, row count, and missing values against the original JSON. Test a record with a comma, quote, or line break in a field to make sure the CSV writer escapes it properly.
The sample should produce two rows, with shipment IDs 0004 and 0012. Confirm that the first row’s last status is delivered and the second row’s status is blank before converting a larger export.