Skip to main content

AltF Flow recipe

Convert JSON to CSV with sorted columns

To turn an API response into a spreadsheet, convert the JSON array of objects to CSV. This recipe first formats the JSON with keys sorted A-Z, then converts it, so the CSV columns follow alphabetical order instead of whatever order the API returned. Keys missing from some objects still get a column, with empty cells where absent.

  • Free, no sign-up
  • Runs in your browser
  • Nothing uploaded
  • Share recipes as a link

2 steps · runs in your browser · nothing uploaded

Pipeline

  1. Sort keys A-Z

    6 → 22 lines (+16)
  2. Turn a JSON array of objects into CSV with a header row.

    22 → 4 lines (-18)

6lines34words246chars

4lines7words146chars-2 lines vs input

The 2 steps in this recipe

  1. 1

    Format JSON - Sort keys A-Z

    Pretty-print JSON with indentation, optionally sorting keys.

  2. 2

    JSON to CSV

    Turn a JSON array of objects into CSV with a header row.

Change any option in the workspace above, switch a step off to compare, or add your own steps. Save it to reuse it, or share the recipe as a link.

Worked example

Before
[
  { "name": "Alex Sample", "id": 3, "email": "alex@example.com" },
  { "id": 7, "email": "riley@example.org", "name": "Riley Test", "plan": "pro" },
  { "email": "jamie@example.net", "name": "Doe, Jamie", "id": 9,
    "tags": ["beta", "eu"] }
]
After
email,id,name,plan,tags
alex@example.com,3,Alex Sample,,
riley@example.org,7,Riley Test,pro,
jamie@example.net,9,"Doe, Jamie",,"[""beta"",""eu""]"

Why sort keys first

JSON to CSV builds its header from the keys in the order it meets them. When objects list keys in different orders, the columns follow the first object, which can be awkward to compare between exports. Sorting keys with Format JSON makes the column order stable. Keys that appear only in later objects, like plan and tags here, are still added as extra columns.

How values are written

  • Values containing a comma, quote or line break are wrapped in double quotes, as CSV requires.
  • Nested objects and arrays are written as compact JSON inside one cell.
  • null and missing values become empty cells.
  • Choose Semicolon as the delimiter for spreadsheet apps set to a European locale.

JSON to CSV, sorted columns: questions and answers

Can I keep the original column order?

Yes. Delete the Format JSON step or turn off Sort keys A-Z.

Does it flatten nested objects into separate columns?

No. A nested object stays as JSON text in one cell. Use a JSON flatten tool first if you need dotted column names.

What if the JSON is a single object?

It is treated as one row, giving a header line and one data line.

More recipes like this

Every step you can add (41)

Clean up

  • Trim whitespace
  • Trim every line
  • Remove empty lines
  • Collapse repeated spaces
  • Remove line breaks
  • Strip HTML tags
  • Straighten smart quotes
  • Remove accents
  • Remove punctuation
  • Remove emoji
  • Remove non-ASCII characters

Change case

  • Change case
  • Make URL slugs

Lines

  • Sort lines
  • Remove duplicate lines
  • Keep only duplicated lines
  • Compare with another list
  • Count repeated lines
  • Reverse line order
  • Shuffle lines
  • Keep a range of lines
  • Truncate long lines
  • Wrap at a width
  • Split into lines
  • Join lines

Find and filter

  • Find and replace
  • Filter lines
  • Remove words or characters

Extract

  • Extract

Data and formats

  • Format JSON
  • Minify JSON
  • CSV to JSON
  • JSON to CSV
  • Lines to JSON array
  • JSON array to lines

Encode and decode

  • Encode or decode

Build output

  • Add prefix / suffix
  • Quote each line
  • Number lines
  • Apply a line template
  • Add timestamp
What each step does, with its options

AltF Flow runs entirely in your browser. Your text is never sent to AltFTool; saved recipes stay in this browser and shared links carry the steps only.