How to Use JSON

Memorize the basic syntax rules., Enter information as name/value pairs., Enclose objects in curly braces., Create arrays for multiple objects., Recall the data later on.

5 Steps 2 min read Medium

Step-by-Step Guide

  1. Step 1: Memorize the basic syntax rules.

    JSON is used to store data, similar to XML.

    It is based on the JavaScript object notation syntax.

    There are four basic syntax rules for JSON.

    If you can memorize these rules, then you should be able to write JSON objects from scratch with ease:
    Data is in name/value pairs Commas are used to separate data Objects are contained by curly braces Arrays are contained by square brackets
  2. Step 2: Enter information as name/value pairs.

    JSON is based around the pair structure for data.

    Each entry will need to have a name with a value attached.

    This value can be a number, a string, a Boolean (true/false), an array, an object, or null.

    See above for an example of a simple data pair: , You can combine multiple data pairs into a single object for easy reference later on.

    Surround the object with curly braces and separate data pairs with a comma.

    See the example above: , You can create basic databases by placing multiple objects into one array.

    This will let you pull up any part of the array later on in the program.

    See the example above for an object called "Cities Visited" containing an array of the cities: , Once you've created the JSON object, you can use JavaScript to pull that data back and display it.

    You simply need to call the database and point to which entry in the array you want.

    See the example above to return the second City from the array above.
  3. Step 3: Enclose objects in curly braces.

  4. Step 4: Create arrays for multiple objects.

  5. Step 5: Recall the data later on.

Detailed Guide

JSON is used to store data, similar to XML.

It is based on the JavaScript object notation syntax.

There are four basic syntax rules for JSON.

If you can memorize these rules, then you should be able to write JSON objects from scratch with ease:
Data is in name/value pairs Commas are used to separate data Objects are contained by curly braces Arrays are contained by square brackets

JSON is based around the pair structure for data.

Each entry will need to have a name with a value attached.

This value can be a number, a string, a Boolean (true/false), an array, an object, or null.

See above for an example of a simple data pair: , You can combine multiple data pairs into a single object for easy reference later on.

Surround the object with curly braces and separate data pairs with a comma.

See the example above: , You can create basic databases by placing multiple objects into one array.

This will let you pull up any part of the array later on in the program.

See the example above for an object called "Cities Visited" containing an array of the cities: , Once you've created the JSON object, you can use JavaScript to pull that data back and display it.

You simply need to call the database and point to which entry in the array you want.

See the example above to return the second City from the array above.

About the Author

A

Alexander Patel

Writer and educator with a focus on practical DIY projects knowledge.

71 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: