Local-first tools. Your files and text stay in your browser.

data guide

CSV vs JSON: choosing a format for your data

CSV and JSON solve different problems. Compare types, nesting, size, encoding and conversion pitfalls before exporting data for Excel or an API.

Reviewed December 3, 2026 · TinkerFern editorial

CSV and JSON both carry structured data, but they make different promises. CSV promises a rectangle that a spreadsheet can open. JSON promises typed values and nested structure that code can consume. Most conversion bugs come from ignoring that difference.

What CSV actually represents

CSV is a family of conventions, not one strict format. RFC 4180 describes the common case:

  • Fields are separated by commas.
  • Records are separated by line breaks.
  • A field containing a comma, quote or newline must be wrapped in double quotes.
  • A double quote inside a quoted field is written as two double quotes.

There is no type system. Every value arrives as text, and the reader decides whether 00123 is a number, a product code or a phone number. There is also no standard way to represent a nested object, a list of tags or a null value distinct from an empty string.

Delimiters vary by locale. A spreadsheet in a comma-decimal locale may expect semicolons, and tabs are common in exports. If the delimiter is wrong, every row collapses into one column.

What JSON represents

JSON has explicit types: string, number, boolean, null, array and object. Keys are strings, nesting is natural, and a parser rejects malformed input instead of guessing.

That precision has costs:

  • Keys repeat on every record, so flat data is larger than the equivalent CSV.
  • JSON has no comments in the standard grammar.
  • A parser is stricter: trailing commas, unquoted keys and NaN are invalid.
  • Numbers are not a single universal type. Very large integers can lose precision when a consumer stores them as floating point.

For a configuration file, an API response or a document with nested fields, JSON is usually the better fit. For a flat table that an analyst will sort and filter, CSV is usually better.

A side-by-side comparison

Question CSV JSON
Shape Rows and columns Arbitrary tree
Types Text, interpreted by the reader Explicit
Nesting Not standard Native
Human editing Easy in a spreadsheet Possible but noisier
Streaming Line-oriented Requires a parser or JSON Lines
Size for flat rows Smaller Larger
Schema Implicit in the header Implicit in the payload

Neither format carries a schema by itself. If a column is optional or a field can be null, document that in the producer and validate it in the consumer.

Conversion pitfalls

Converting JSON to CSV looks mechanical until the data is not rectangular. A good converter should define its behaviour:

  • Union headers. Different objects may have different keys. The header should include every key, in first-seen order, with blanks where a record lacks one.
  • Nested objects. Flatten with dot paths such as user.address.city, or serialize the nested value as JSON in one cell. Pick one and show it in the interface.
  • Arrays. Joining with a separator is convenient but lossy if values can contain that separator. Serializing as JSON is safer; joining is friendlier for spreadsheets.
  • Null versus empty. CSV cannot distinguish them reliably. Decide whether null becomes an empty cell or the text null.
  • Type inference. Treat it as opt-in. Leading zeros, long IDs, phone numbers and dates are safer as strings.
  • Formula injection. A cell beginning with =, +, - or @ may execute in a spreadsheet. Prefix risky cells with an apostrophe or quote them according to your policy.

Going the other direction, CSV to JSON needs a header decision. With headers, each row becomes an object; without them, each row becomes an array. Duplicate header names are ambiguous, and quoted multiline cells must be parsed by a real CSV parser rather than split on commas.

Encoding and Excel

UTF-8 is the sane default. Excel on Windows may still assume a legacy code page for a plain CSV, which turns accented text into mojibake. Adding a UTF-8 byte order mark (BOM) often fixes the display, but some tools treat the BOM as part of the first header name. Test with the application that will open the file.

JSON is defined as Unicode and is normally exchanged as UTF-8 without a BOM. If a JSON file starts with a BOM, some parsers reject it.

Line endings are another small compatibility trap. RFC 4180 uses CRLF, while Unix tools prefer LF. Most readers accept both, but binary comparisons and checksums will not.

A practical default

Use CSV when the destination is a spreadsheet, the data is flat, and a human will inspect or edit it. Use JSON when the destination is an application, the data is nested, or types matter. When you need both, keep one canonical source and generate the other as an export rather than editing two copies.

The JSON to CSV converter exposes flattening, delimiter and BOM options. The CSV to JSON converter handles quoted cells and optional type inference. If the source JSON is hard to read before conversion, format it first with the JSON formatter.

Further reading: RFC 4180 for CSV, RFC 8259 for JSON, and the OWASP guidance on CSV injection.

Tools mentioned in this guide

Apply the advice with a tool that runs locally.

Continue with a related explainer from the same topic.

All guides →

← All guides · RSS feed

Privacy and cookie settings

This build loads no advertising scripts and no analytics vendor. If analytics is enabled by the owner, it sends only allowlisted event names and tool IDs, never your text, files or generated output.

Analytics
Disabled in this build
Advertising
Disabled in this build
Local storage
Theme, favorite tool IDs, recent tool IDs