Skip to main content

AltF Flow recipe

Convert messy CSV to clean JSON

CSV pasted from a spreadsheet or email often has blank rows and spaces around values, which end up inside the JSON strings. This recipe trims the text, removes empty rows, trims each line, strips spaces around every comma and then converts the CSV to a JSON array of objects, using the first row as keys.

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

5 steps · runs in your browser · nothing uploaded

Pipeline

  1. Remove spaces and blank lines from the start and end of the whole text.

    7 → 5 lines (-2)
  2. Remove all

    5 → 4 lines (-1)
  3. Remove leading and trailing spaces from each line.

    4 → 4 lines
  4. Find: [ \\t]*,[ \\t]*, Replace with: ,, Regular expression

    4 → 4 lines
  5. First row is a header

    4 → 17 lines (+13)

7lines18words134chars

17lines28words264chars+10 lines vs input

The 5 steps in this recipe

  1. 1

    Trim whitespace

    Remove spaces and blank lines from the start and end of the whole text.

  2. 2

    Remove empty lines - Remove all

    Delete blank lines, or squeeze runs of blank lines down to one so paragraphs stay apart.

  3. 3

    Trim every line

    Remove leading and trailing spaces from each line.

  4. 4

    Find and replace - Find: [ \\t]*,[ \\t]*, Replace with: ,, Regular expression

    Replace text everywhere. Supports regular expressions with $1 back-references.

  5. 5

    CSV to JSON - First row is a header

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

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 , email , plan
  Alex Sample, alex@example.com , pro

Riley Test ,riley@example.org, free
"Doe, Jamie", jamie@example.net ,team
After
[
  {
    "name": "Alex Sample",
    "email": "alex@example.com",
    "plan": "pro"
  },
  {
    "name": "Riley Test",
    "email": "riley@example.org",
    "plan": "free"
  },
  {
    "name": "Doe,Jamie",
    "email": "jamie@example.net",
    "plan": "team"
  }
]

Why clean before converting

The CSV to JSON step keeps every character between commas, so " alex@example.com " would become a value with spaces, and a header of "email " would become a key with a trailing space. Removing spaces around commas first gives clean keys and values. Blank lines are dropped so they do not become empty objects.

Quoted fields and caveats

  • The parser follows RFC 4180: quoted fields, doubled quotes and line breaks inside quotes are supported.
  • The comma cleanup also touches commas inside quoted values, turning "Doe , Jamie" into "Doe,Jamie". Remove step 4 if your quoted values contain meaningful spaces next to commas.
  • All values come out as strings; numbers are not converted.
  • For semicolon or tab files, change the delimiter on the last step and the character in step 4.

CSV to JSON with cleanup: questions and answers

What if my CSV has no header row?

Turn off First row is a header and the output becomes an array of arrays instead of objects.

What happens to rows with missing cells?

Missing cells become empty strings for the remaining header keys, so every object has the same keys.

Can I minify the JSON afterwards?

Yes. Add Minify JSON as a final step.

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.