JSON Rules

JSON Rules

JSON has a certain set of rules to follow. They are

#1 JSON Keys must be double quoted

Example

HTML Editor
// Invalid JSON [ { name: "Mike", age: 36}, { name: "Alex", age: 30} ] // Valid JSON [ { "name": "Mike", "age": 36}, { "name": "Alex", "age": 30} ]

#2 JSON Values cannot be left blank

Example

HTML Editor
// Invalid JSON [ { "name": "Mike", "age": }, { "name": "Alex", "age": 30} ] // Valid JSON [ { "age": null}, { "age": 0}, { "age": ""}, { "age": "null"}, { "age": []} ]

#3 JSON data should not be ended with semicolon

Example

HTML Editor
// Invalid JSON [ { "name": "Mike", "age": 36}, { "name": "Alex", "age": 30} ]; // Valid JSON [ { "name": "Mike", "age": 36}, { "name": "Alex", "age": 30} ]

#4 JSON String Values cannot be single quoted

Example

HTML Editor
// Invalid JSON [ { "name": 'Mike', "age": 36}, { "name": 'Alex', "age": 30} ] // Valid JSON [ { "name": "Mike", "age": 36}, { "name": "Alex", "age": 30} ]

#5 JSON by itself cannot perform any Mathematical operation

Example

HTML Editor
// Invalid JSON [ { "name": "Mike", "age": 30 + 6}, { "name": "Alex", "age": 30} ]; // Valid JSON [ { "name": "Mike", "age": "30 + 6"}, { "name": "Alex", "age": "30"} ]

#6 JSON cannot have comma at the end of last object/data

Example

HTML Editor
// Invalid JSON [ { "name": "Mike", "age": "30"}, { "name": "Alex", "age": "30"}, ] // Valid JSON [ { "name": "Mike", "age": "30"}, { "name": "Alex", "age": "30"} ]

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