Skip to content

What are JSON and CSV?

JSON and CSV are the two most popular ways of storing data in a plain text file. CSV is a table: rows and columns separated by commas. JSON is data split into fields, lists and nested sections - like a filled-in form.

In short

  • CSV - a simple table in a text file. Excel opens it, and almost every program can export it.
  • JSON - data of any shape. It is the language apps and APIs talk to each other in.
  • Both are plain text, so Notepad opens them - but one wrong character can break them.

A shopping list and a form

CSV is a shopping list written as a table: each row is a product, a quantity and a price. Simple, readable, every row looks the same.

JSON is more like a filled-in order form: customer details, below them an address with a street and a postcode, then a list of products, each with fields of its own. Sections can have sub-sections, lists can be of any length. A table cannot hold that comfortably.

CSV: a table in text

CSV (Comma-Separated Values) looks like this:

product,quantity,price
Milk,2,1.29
Bread,1,2.45

The first row usually holds the headings, the rest is data. The name says commas, but in countries that use a comma as the decimal separator, spreadsheets expect semicolons instead. Open a comma-separated file there and everything lands in a single column - so if a file looks broken, check the separator first.

Other common CSV traps:

  • Accented characters - seeing "é" instead of "é"? The file is saved in UTF-8 and Excel opened it in an older encoding. Importing through Data - From Text/CSV and choosing UTF-8 fixes it.
  • Excel "fixing" your data - it strips leading zeros (007 becomes 7) and turns some values into dates (1-2 becomes 2 January, or 1 February, depending on your locale).
  • Text containing the separator - if a description contains a comma, the whole value must be in quotes, or the columns shift.

You usually get CSV as an export: from your bank, your shop, your accounting system, Google Sheets. And to turn that data into a chart quickly, just paste the table into Charts.

JSON: data with indentation

JSON (JavaScript Object Notation) looks like this:

{
  "customer": "Anna Smith",
  "address": {
    "city": "Leeds",
    "postcode": "LS1 4AP"
  },
  "products": [
    { "name": "Milk", "quantity": 2 },
    { "name": "Bread", "quantity": 1 }
  ]
}

Curly braces are an object (named fields), square brackets are a list. Inside you can have text in quotes, numbers, true/false and null. That is it - the whole specification fits on one page.

You will find JSON in API responses, in program configuration files and in the files apps save your work to. It has its traps too - it is a very literal format:

  • a comma after the last item in a list is an error,
  • text needs double quotes; single quotes do not count,
  • there are no comments at all.

One wrong character and the program refuses to load the whole file. That is when a JSON formatter and validator helps: it points to exactly where it breaks.

Which one to pick

  • The data is a flat table (customers, transactions, measurements) and someone will look at it in Excel - CSV.
  • The data has structure (an order with products, settings with sections) or is going into another program - JSON.

In other words: CSV for people with spreadsheets, JSON for programs. Though of course one can be converted into the other, when the data allows it.

When it matters to you

  • You export data from your bank, shop or system and open it in Excel - watch the separator and the encoding.
  • You connect systems or commission an integration - the data will flow as JSON.
  • You are learning to code - JSON is one of the first formats worth knowing by heart.

API, file extension, character encoding, UTF-8, XML.

Advertisement