json
  1. json-example

JSON Example

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.

Syntax

{
    "key": "value",
    "list": [1, 2, 3],
    "obj": {
        "name": "John",
        "age": 25
    }
}

Example

{
    "name": "Jane",
    "age": 30,
    "hobbies": ["reading", "traveling"],
    "address": {
        "city": "New York",
        "state": "NY"
    }
}

Output

{
    "name": "Jane",
    "age": 30,
    "hobbies": [
        "reading",
        "traveling"
    ],
    "address": {
        "city": "New York",
        "state": "NY"
    }
}

Explanation

In this example, we have a JSON object with the following key-value pairs:

  • "name": "Jane"
  • "age": 30
  • "hobbies": ["reading", "traveling"]
  • "address": {"city": "New York", "state": "NY"}

The "hobbies" key has a value of an array of strings, and the "address" key has a value of another JSON object.

Use

JSON is commonly used for data exchange between systems. It is also used for storing and transmitting configuration data, web APIs, and more.

Important points

  • JSON stands for JavaScript Object Notation.
  • JSON uses a key-value pair format similar to JavaScript objects.
  • Keys must be strings and values can be strings, numbers, arrays, objects, or boolean values.
  • JSON is commonly used for data exchange between systems.

Summary

In this example, we learned about the syntax of a JSON object, saw an example of a simple JSON object with a few key-value pairs, and its output. We also discussed its uses and some important points to keep in mind while working with JSON.

Published on: