I am writing a JSON file, but I am not sure about which of the following formats is the correct one?
Quoting variable names and all string values
{
"class": {
"number": 2,
"student": {
"name": "Tom",
"age": 1
},
"student": {
"name": "May",
"age": 2
}
}
}
or
Quoting only string values
{
class: {
number: 2,
student: {
name: "Tom",
age: 1
},
student:
{
name: "May",
age: 2
}
}
}
In JSON each property name and each string value must be enclosed in double quotation marks ( " ). In JavaScript notation, a property name used in an object literal can be, but need not be, enclosed in double quotation marks. It can also be enclosed in single quotation marks ( ' ).
JSON Syntax RulesData is in name/value pairs. Data is separated by commas. Curly braces hold objects. Square brackets hold arrays.
JSON stands for JavaScript Object Notation. It is a lightweight data-interchange format and fully described on www.json.org. JSON is based on JavaScript but the format is stricter. JSON requires double quotes around keys whereas JavaScript does not.
The first is valid, if you're unaware you can validate your JSON output online pretty easily here: http://www.jsonlint.com/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With