JSON Syntax

String and Number

In the following example, we will learn how to use string value and number value in JSON.

Note: name is in string and age is in number.

Example

HTML Editor
[ { "name": "Mike", "age": 36 }, { "name": "Alex", "age": 30 } ]

Array

In the following example, we will learn how to use array value in JSON.

Note: friends is in array.

Example

HTML Editor
[ { "name": "Mike", "age": 36, "friends": ["John", "Antony"] }, { "name": "Alex", "age": 30, "friends": ["Jade", "Jasmine"] } ]

Object

In the following example, we will learn how to use object value in JSON.

Note: id is in object.

Example

HTML Editor
[ { "name": "Mike", "age": 36, "id": { "eyes": "brown", "hair": "blonde" } }, { "name": "Alex", "age": 30, "id": { "eyes": "blue", "hair": "brunette" } } ]

Array within Object

In the following example, we will learn how to use array within object in JSON.

Note: hair is in array and id is in object. So, array within object.

Example

HTML Editor
[ { "name": "Mike", "age": 36, "id": { "eyes": "brown", "hair": ["blonde", "golden"] } }, { "name": "Alex", "age": 30, "id": { "eyes": "blue", "hair": ["brunette", "brown"] } } ]

Object within Array

In the following example, we will learn how to use object within array in JSON.

Note: jade and antony are in objects and friends is in array. So, object within array.

Example

HTML Editor
[ { "name": "Mike", "age": 36, "friends": [{ "jade": { "gender": "female", "age": 25 }, "antony": { "gender": "male", "age": 35 } }] } ]

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author