50%

JSON Cheat Sheet

A JSON cheat sheet typically includes the basic syntax rules and examples for creating and working with JSON data structures. It may also include information on everyday use cases and best practices for working with JSON in various programming languages and environments.

1. Basic :-

Example
{
    "superheros": {
        "hero": [
        {
            "id": "1",
            "firstName": "Fast ",
            "lastName": "Kick"
        },
        {
            "id": "2",
            "firstName": "Hawk ",
            "lastName": "Storm"
        }
       ]
      }
}
String
\" Double quote
\/ Forward slash
\b Backspace
\\ Backslash
\u Trailed by four hex digits
\n Newline
\f Form feed
\r Carriage return
\t Tab
Types
Number Double precision floating-point
String Series of characters
Boolean True or false
Arrray Ordered sequence of values
Object Object is a collection of key-value pairs
Null Null or Empty
Value String, Number, Boolean, null etc
Number
Integer Digits 1 to 9, 0 and positive or negative
Exponent Exponent like E, e, E+, e+
Fraction Fractions like 0.6, 3.6, 9.45
{
    "positive" : 24,
    "negative" : -8,
    "exponent" : 2.0E+3,
    "fraction" : 09.36,
    "zero" : 0
}

Learn Json :-

2. Arrays :-

Array

A JSON (JavaScript Object Notation) array is a collection of values enclosed in square brackets [] and separated by commas. The values in a JSON array can be any data type supported by JSON, such as strings, numbers, objects, arrays, and Boolean values.


  ["apple", "banana", "Mango","Kiwi"]
2D Array
{
    "my_array": [
        [3, 1, 3],
        [4, 9, 6],
        [5, 8, 2, 0],
        [7, 12]
    ]
}

3. Objects :-

Objects Of Objects

These nested objects can also contain properties that are either values or nested objects themselves.

{
    "villan1": {
        "firstName": "Spencer ",
        "lastName": "Church"
    },
    "villan2":{
        "firstName": "Emma",
        "lastName": "Holland"
    }
}
Array Of Objects

An array of objects is simply an array in which each element of the array is an object. An object is a collection of key-value pairs.

 {
    "children": [
        {"name": "John Doe", "city": "New York"},
        {"name": "Chris Hood", "city":"Los Angeles"}
    ]
}
Objects Of Array
 {
    "empty_array": [],
    "attribute": ["A1", "A2"],
    "methods": ["getter", "setter"]
}

4. Access JSON :-

Access Object
let myObj = {
    "name": "John",
    "last": "Doe",
    "gender": "M",
    "salary": 72000,
    "age": 36,
    "married": true
};
myObj.name "John"
myObj.last "Doe"
myObj.age 36
Access Array of Objects
let myArr = [
    {
        "name": "John",
        "last": "Doe",
        "age": 39,
    },
    {
        "name": "Tom",
        "last": "Cruise",
        "age": 45,
    },
    {
        "name": "Hood",
        "last": "James",
        "age": 29,
    }
    ];
myArr[2].name "Hood"
myArray[1][2] 45
Access Array
 let myArray = [
    "John",
    "Doe",
    69000,
    36,
    "M",
    true
];
myArray[0] "John"
myArray[1] "Doe"
myArray[3] 36
Access Nested
 let myObj = {
    "ref": {
        "name": 0,
        "last": 1,
        "age": 2,
    },
    "jdoe": [
        "John",
        "Doe",
        39,
    ],
    "tsmith": [
        "Tom",
        "Smith",
        42,
    ]
};
myObject.ref.last 2
myObj.tsmith[2] 42

JSON CheatSheet Online


A JSON cheat sheet is a reference guide or quick reference help that provides a brief overview of the syntax and structure of JSON (JavaScript Object Notation).

A JSON cheat sheet typically includes the following:

  • JSON Syntax: It outlines the basic rules and conventions for writing JSON, such as the use of curly braces ({}) to define objects and square brackets ([]) to define arrays.
  • JSON Data Types: It lists the supported data types in JSON, including strings, numbers, booleans, null, objects, and arrays.
  • JSON Objects: It explains how to define key-value pairs within a JSON object and provides examples of nested objects.
  • JSON Arrays: It illustrates how to define and use arrays in JSON, including examples of arrays containing different data types or nested arrays.
  • JSON Special Characters: It describes how to escape special characters within JSON strings, such as double quotes (") or backslashes (\), using the backslash (\) character.
  • JSON Example: It presents a sample JSON structure or snippet to demonstrate how the various elements discussed in the cheat sheet fit together.

The JSON cheat sheet is a handy resource for developers and programmers who work with JSON data, allowing them to quickly reference the syntax and structure without consulting lengthy documentation or references.

Know more about JSON