What is JSON

Language independent way to represent data

JSON stands for JavaScript Object Notation. JSON is a lightweight format for storing and transporting dataJSON is often used when data is sent from a server to a web page JSON is "self-describing" and easy to understand

Sample JSON

Following JSON contains address information with title "Mailing Address"

                            
                                {
                                    "title": "Mailing Address",
                                    "Name": "Sidd B",
                                    "country": "Japan",
                                    "city": "Tokyo",
                                    "zip": 334455,
                                    "phone": [
                                        {
                                            "content": "123456",
                                            "type": "home"
                                        },
                                        {
                                            "content": "222222",
                                            "type": "mobile"
                                        },
                                        {
                                            "content": "33333",
                                            "type": "mobile"
                                        }
                                    ]
                                }
                            
                            

Following are the data types in JSON

JSON Datatypes

  • string
  • number
  • object
  • array
  • boolean
  • null

JSON Syntax Rules

  • Data is in name/value pairs
  • Data is separated by commas
  • Curly braces hold objects
  • Square brackets hold arrays

What is JSON Schema

JSON Schema is like XML Schema, it helps in describing the JSON Document. It can be used to validate the JSON payload.

following json schema describes a movie object.

Sample JSON Schema


{
    "$id": "https://jsonzone.com/movie.schema.json",
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "title": "Movie",
    "type": "object",
    "properties": {
        "name": {
        "type": "string",
        "description": "Name of the movie."
        },
        "director": {
        "type": "string",
        "description": "Movie director name."
        },
        "release": {
        "type": "string",
        "description": "released date."
        },
        "budget": {
        "description": "Movie budget in rounded million USD.",
        "type": "integer",
        "minimum": 0
        },
        "rating": {
        "description": "Movie Rating on rottentomatoes.com.",
        "type": "number",
        "minimum": 0
        }
    }
}
Valid JSON string as per the above schema.

{
    "name": "Avatar",
    "director": "James Cameron",
    "release": "December 16, 2022",
    "budget": 250,
    "rating": 9.0   
}

Where JSON Schema can be used?

following are some of the uses of JSON Schema

  • Validating JSON
  • Generating UI from schema
  • Generating JSON data based on the schema
  • Generating Open API artifacts