What Is JSON and What Is It Used For?

If you work with websites, apps or data, you will see JSON everywhere. It is in API responses, settings files and data downloads. The good news is that JSON is simple. You can learn the basics in a few minutes.

This guide explains what JSON is, what it looks like and the few rules it follows. You don’t need any coding experience.

Quick answer: JSON (JavaScript Object Notation) is a simple text format for storing and sending data. It writes data as names with values, and as lists. Both people and computers can read it easily.

What does JSON stand for?

JSON stands for JavaScript Object Notation. The name comes from JavaScript, the language that runs in web pages. JSON borrows its style from the way JavaScript writes data.

But JSON is not tied to JavaScript. Almost every programming language can read and write it, including Python, Java, C#, Go and PHP. That is a big reason it is so popular.

A JSON file is a plain text file. Its name usually ends in .json. When JSON is sent over the web, it gets the label application/json. Then the program on the other end knows what it is getting.

What does JSON look like?

Here is a small example. It describes one person:

{
  "name": "Maria",
  "age": 34,
  "isMember": true,
  "languages": ["English", "Spanish"],
  "address": {
    "city": "Madrid",
    "country": "Spain"
  },
  "phone": null
}

Even if you have never seen JSON before, you can probably read this. Let’s go through the parts.

  • Curly braces { } hold an object. An object is a group of named values.
  • Keys are the names on the left, like "name". A key is always text in double quotes.
  • Values come after the colon, like "Maria" or 34.
  • Square brackets [ ] hold an array. An array is an ordered list of values.
  • Commas separate each pair, and each item in a list.

Objects and arrays can sit inside each other. In the example, address is an object inside the main object. This is called nesting. It lets JSON describe detailed data in a neat way.

What kinds of values can JSON hold?

JSON has only six types of value:

  • String: text in double quotes, like "Madrid".
  • Number: a whole or decimal number, like 34 or 9.99.
  • Boolean: true or false.
  • Null: null, which means “no value”.
  • Array: a list in square brackets.
  • Object: named values in curly braces.

That’s the whole list. There is no special type for dates, for example. Our guide to JSON data types explains each one in more detail.

What are the rules of JSON?

JSON is strict. One small mistake can stop a program from reading the whole file. These are the rules people break most often:

  1. Keys must be in double quotes. { name: "Maria" } is not valid JSON.
  2. Strings must use double quotes, not single quotes.
  3. There is no comma after the last item in an object or array.
  4. There are no comments. You can’t add notes inside the data.
  5. true, false and null are always written in lowercase.

If a file breaks any of these rules, it is called invalid. To check your JSON, paste it into the JSON Validator. It shows the line and column of an error. It also explains the error in plain English. For a list of usual mistakes, see the most common JSON errors.

Where is JSON used?

JSON is small, easy to read and supported almost everywhere. You will find it in many places:

  • APIs. An API (application programming interface) is a way for programs to talk to each other. An app may ask a server for data, such as the weather. The answer often comes back as JSON.
  • Settings files. Many tools keep their settings in JSON. For example, JavaScript projects have a file called package.json.
  • Data downloads. Many apps and services let you download your data as JSON files.
  • Databases. Some databases store each record as a JSON-like document. Many others can store JSON in a column.
  • AI tools. Chatbots and other AI models are often asked to reply in JSON, so a program can use the answer.

How is JSON different from XML and YAML?

JSON is not the only data format. XML is an older format that uses tags, a bit like HTML. YAML is often used for settings files. It uses indentation (spaces at the start of a line) instead of brackets.

JSON is usually shorter than XML and stricter than YAML. To compare them side by side, read JSON vs XML and JSON vs YAML.

How can I read JSON more easily?

Small JSON is easy to read. But real JSON is often long. It may also be all on one line, with no spaces. That is very hard for people to follow. There are two simple fixes:

  • The JSON Formatter adds line breaks and indentation (spaces at the start of each line). This makes the structure clear.
  • The JSON Viewer shows the data as a tree. You can open and close each object and array, and see how many items each one holds.

Both tools are free and run in your browser.

Common questions

Is JSON a programming language?

No. JSON is a data format, not a language. It can’t run code or make decisions. It only describes data.

How do I open a JSON file?

A JSON file is plain text, so any text editor can open it, such as Notepad or VS Code. For an easier view, open it in a JSON viewer that shows the data as a tree. Our guide on how to open a JSON file covers Windows, Mac and phones.

Is JSON the same as a JavaScript object?

No, but they look alike. JSON is text with stricter rules. Keys need double quotes, and things like functions and comments are not allowed. In JavaScript, JSON.parse() turns JSON text into an object.

Can JSON have comments?

No. Standard JSON does not allow comments. Some tools accept a different form called JSONC (JSON with Comments). But normal JSON readers reject it. See JSON and comments for other ways to add notes.