JSON to CSV: Keep Columns From Later Rows

When objects have different keys, a CSV exporter can use the first object to select columns. If a field appears only in a later object, check the header before you import the result elsewhere.

Worked example

Uneven input and observed output

[
  {
    "name": "Maya"
  },
  {
    "name": "Alex",
    "team": "Support"
  }
]

name
Maya
Alex

Aligned JSON input

[
  {
    "name": "Maya",
    "team": null
  },
  {
    "name": "Alex",
    "team": "Support"
  }
]

Actual corrected CSV

name,team
Maya,
Alex,Support

Steps

  1. List the columns you want in the CSV and decide how to represent missing values.
  2. Give every row the same keys, including the first. The example uses null for a missing team, which becomes an empty field in the export.
  3. Convert the aligned objects. Verify the header includes each expected column and check one row that originally introduced a new key.

What to check

  • An empty CSV cell may mean missing or empty depending on the destination. Preserve a separate status column if that distinction matters.
  • Decide how to represent nested fields before flattening; use columns such as address_city where the receiving schema expects them.

Try the aligned data in the JSON to CSV converter