Sobes.tech
Intern

What is JSON?

sobes.tech AI

Answer from AI

JSON (JavaScript Object Notation) is a lightweight data interchange format based on a subset of JavaScript syntax. It is used to represent structured data in a human-readable form and is also easy for machines to parse.

The main elements of JSON are:

  1. Objects: Unordered sets of key-value pairs. The key is a string, and the value can be any JSON data type. Objects are enclosed in curly braces {}. Example:
    {
      "name": "Ivan",
      "age": 30
    }
    
  2. Arrays: Ordered lists of values. Arrays are enclosed in square brackets []. Values can be of different types. Example:
    [
      "Apple",
      "Banana",
      "Orange"
    ]
    
  3. Values: Can be of the following types:
    • String: A sequence of characters in double quotes "".
    • Number: An integer or floating-point number.
    • Boolean: true or false.
    • null: An empty value.
    • Object.
    • Array.

Example of a complete JSON document:

{
  "user": {
    "id": 123,
    "name": "Peter",
    "surname": "Petrov",
    "active": true,
    "roles": ["user", "admin"],
    "address": null,
    "contacts": {
      "email": "petrov@example.com",
      "phone": "111-222-333"
    }
  },
  "products": [
    {
      "code": "A1",
      "name": "Laptop",
      "price": 1200.50
    },
    {
      "code": "B2",
      "name": "Mouse",
      "price": 25.00
    }
  ]
}

JSON is widely used for data exchange between server and web application (AJAX), in configuration files, and as a format for storing unstructured and semi-structured data. In Java, libraries such as Jackson, Gson, org.json, and others are used to work with JSON, allowing conversion between JSON and Java objects (deserialization) and vice versa (serialization).

What is JSON? — Java - sobes.tech