How to convert CSV to JSON and back

You exported your store's orders as a CSV file, and your developer wants JSON. Or a platform sent you JSON and you want to open it in Excel. Converting by hand is impractical, and a bad conversion can strip zeros from phone numbers or garble Arabic letters.

Published · 2 min read

From CSV to JSON

Each row becomes an object, and the column names become its keys. Commas, quotes and line breaks inside cells are handled by the usual CSV rules.

Worked example

A table with the columns order, customer and amount, and two rows: 1001, Sara and 120, then 1002, Omar and 80.

It becomes an array of two objects, the first holding "order": "1001" and "amount": "120".

Notice that 120 stays text in quotes, because number conversion is off by default.

Why do numbers stay as text?

Because converting them can do harm: a number like 0501234567 becomes 501234567 and loses its leading zero, and so do postcodes and product codes. Turn on number conversion only when every numeric column holds real amounts or quantities.

From JSON to CSV

Nested data is flattened into columns with combined names. So an object with an id, a customer holding a name and a city, and a tags array of two items gives the columns: id, customer.name, customer.city, tags.0 and tags.1.

How to do it

  1. Open the CSV and JSON converter and paste text or open a file.
  2. Choose the direction and the delimiter.
  3. Check the warnings: rows with a problem are listed by number.
  4. Copy or download the result.

Garbled Arabic letters

Files are read as UTF-8 by default. If you get a message that the file is not UTF-8, it is most likely an old Arabic Excel export. Choose the Windows-1256 encoding and open it again, and the letters come out right.

What to know

  • The limit is 5 MB per file or text.
  • A null value and a missing key both become an empty CSV cell, and cannot be told apart afterwards.
  • CSV does not keep data types, so everything in it is text.

After converting to JSON, you can review and format it with the JSON formatter and validator. If the CSV file holds expenses, the better tool for summarising it is the Expense summary generator.

Common questions

Will the CSV file open in Excel with Arabic intact?

Yes. The file is written as UTF-8 with a marker that helps Excel read Arabic.

Will I lose the zeros in phone numbers?

No, as long as number conversion is off, which is the default.

Are my files uploaded?

No, the conversion runs inside your browser.