Skip to content

What is JSON

JSON (JavaScript Object Notation) is a lightweight data interchange format that is easy for humans to read and write, and for machines to parse and generate. It's commonly used for transmitting data between a server and a web application, but it's also used for configuration files and storing structured data.

Imagine you have a bunch of information you want to organize and store, like a list of people's names, ages, and email addresses. Instead of just writing it down in a document in plain text, JSON allows you to structure this information in a standardized way.

Here's a simple example:

json
{
  "people": [
    {
      "name": "John",
      "age": 30,
      "email": "john@example.com"
    },
    {
      "name": "Alice",
      "age": 25,
      "email": "alice@example.com"
    }
  ]
}

In this example:

It starts with curly braces {} which indicate the beginning and end of the JSON object. Inside the braces, there's a key-value pair: "people": [...]. Here, "people" is the key, and [] denotes an array, which is a collection of objects enclosed in square brackets. Each object within the array represents a person, with keys "name", "age", and "email" corresponding to their respective values.

JSON is popular because it's easy to understand both for humans and computers. It's also flexible enough to represent complex data structures while remaining lightweight and efficient for data exchange.

JSON supports several data types for representing values:

  • String: A sequence of characters enclosed in double quotes. For example: "Hello, World!"

  • Number: A numeric value, which can be an integer or a floating-point number. Numeric values don't have quotes around them. For example: 42 or 3.14.

  • Boolean: Represents either true or false (without quotes), denoting logical true or false values.

  • Array: An ordered collection of values enclosed in square brackets []. Elements within an array can be of any JSON data type, including arrays themselves. For example: [1, 2, 3] or ["apple", "banana", "orange"].

  • Object: An unordered collection of key-value pairs enclosed in curly braces {}. Keys must be strings, and values can be any JSON data type, including objects and arrays. For example: {"name": "John", "age": 30}.

  • Null: Represents a null value, indicating the absence of a value. It's written as the keyword null (without quotes).

These data types allow JSON to represent a wide range of structured data, from simple values like strings and numbers to complex hierarchical data structures like objects containing arrays of objects. JSON's simplicity and flexibility make it suitable for various use cases, including data interchange, configuration files, and storage of structured data.