JSON parent/child CSV roundtrip guide

Edit nested order JSON as CSV and restore it: preserve parent keys, order and null

Split nested order JSON into parent and child CSVs, keep keys, child order, types and null, and change only item B quantity from 3 to 4.

See two parents and three children

The original orders array contains orders 001 and 002, with three items A, B and C. Separate parent and child tables can be restored without a Cartesian product when parent_id and zero-based ordinal stay attached to every child.

ParentChildrenRelationship
0010:A / 1:Btwo items
0020:Cone item

Split parent and child CSVs

parents.csv carries the order ID and note meaning. children.csv carries parent ID, order, SKU and quantity. If a source has no stable key, keep a documented in-file ID and do not mix it with another document. Store column, JSON path, type and null policy in schema/mapping.json.

parent_id=001
ordinal=0 → A
ordinal=1 → B
Keep the parent key with child order.
001.note = null
002.note = ""
A blank is not null proof
Use the mapping manifest to distinguish null from empty string.

Change only item B from 3 to 4

edited-children.csv changes only 001 / ordinal 1 / B from qty 3 to qty 4. Parent ID and note, items A and C, and every ordinal stay unchanged. Total quantity moves from 6 to 7.

RowBeforeAfterChanged path
001 / 1 / Bqty 3qty 4/orders/0/items/1/qty
Everything elseunchangedunchangednone

Compare values, types and relationships

expected.json has two orders, three items and total quantity 7. Check ID and quantity types, child order, 001.note=null, 002.note="", and empty child arrays where applicable. Separate formatting or object-key order differences from value, type and path differences.

orders[0].items[1].qty: 3 → 4
parents: 2 / children: 3 / total qty: 7
orders[0].items stays A, B

Do not auto-repair broken relationships

orphan.csv points to missing parent 999; keep it unresolved and do not invent a parent. duplicate-parent.csv repeats order ID 001; do not silently select the first row. Missing ordinals, untyped blanks and relationship drift should block output for review.

The original JSON and CSVs are fixtures for this guide. In real work, preserve the original and compare before and after independently.

Review with the existing JSON/CSV formatter

  1. Keep the source JSON, parent CSV, child CSV and mapping together.
  2. Use the existing JSON/CSV formatter to assign the parent and child tables.
  3. Load the edited child CSV and change only B quantity to 4.
  4. Before saving, check counts, order, types, null, orphan and duplicate boundaries.
  5. Compare the completed JSON with expected.json by path, without sending input outside the browser.