json

What is JSON

JSON (JavaScript Object Notation) is a lightweight data interchange format that is easy for humans to read and write and easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition – December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.

Here is an example of a JSON object:

{
  "name": "John Smith",
  "age": 30,
  "city": "New York"
}

This JSON object has three key-value pairs:

  • “name”: “John Smith”
  • “age”: 30
  • “city”: “New York”

Each key is a string enclosed in double quotes, and the value can be a string (enclosed in double quotes), a number, or a boolean (true or false). The key-value pairs are separated by commas. JSON objects can also contain arrays and nested objects.

Here is an example of a JSON array:

[1, 2, 3, 4, 5]

This JSON array contains five elements: 1, 2, 3, 4, and 5. JSON arrays can contain elements of any data type, including other arrays and objects.

Here is an example of a JSON object with a nested object:

{
  "name": "John Smith",
  "age": 30,
  "city": "New York",
  "address": {
    "street": "123 Main Street",
    "zipCode": "10001"
  }
}

This JSON object has a nested object as the value of the “address” key. The nested object has two key-value pairs: “street” and “zipCode”.

JSON is often used to transmit data between a server and a web application, as an alternative to XML. It is also commonly used for storing data in a NoSQL database, such as MongoDB.

Comments are closed.