Introduction to JSON

JSON is a lightweight data representation format that is not only easy for humans to read and write but also easy for machines to parse and generate. It is mainly used to transmit data between a server and web application, as well as to store and exchange data.

Understanding JSON Syntax and Data Types

JSON is a combination of two data structures:

Object Object is a collection of unordered key-value pairs, enclosed in curly braces {}. Here, keys must be strings, and values can be strings, numbers, objects, arrays, booleans, or null. Here is a basic syntax for JSON objects,

{
  "name": "John",
  "age": 40,
  "address": {
    "city": "New York",
    "country": "USA"
  }
}

Array Array is a list of ordered values that are enclosed in square brackets []. Here, the values can be strings, numbers, objects, arrays, booleans, or null. Here is a basic syntax for JSON array,

[
  "banana",
  "orange",
  {
    "fruit": "grape",
    "color": "purple"
  },
  35
]