I am confused by reading a lot of JSON tutorials on the Internet (even on STO) and not able to decide what is right and what is wrong related to writing an external JSON file.
I have seen so many instances e.g.
(for a single object tho Adobe Dreamweaver CS5.5 shows syntax error, don't know why)
#1
{
"name" : "Sachin",
"age" : 30,
"country" : "India"
}
#2
For multiple objects:
[
{
"name" : "Sachin",
"age" : 30,
"country" : "India"
},
{
"name" : "Amit",
"age" : 28,
"country" : "USA"
}
]
#3
Some have been seen using single quotes around the objects array and storing the array in a variable like this:
customers = '[
{
"name" : "Sachin",
"age" : 30,
"country" : "India"
},
{
"name" : "Amit",
"age" : 28,
"country" : "USA"
}
]'
#4
A few of them writing above code in the following style:
{
"customers" : [
{
"name" : "Sachin",
"age" : 30,
"country" : "India"
},
{
"name" : "Amit",
"age" : 28,
"country" : "USA"
}
]
}
#5
One more extra sample format added:
{
[
{
"name" : "Sachin",
"age" : 30,
"country" : "India"
},
{
"name" : "Amit",
"age" : 28,
"country" : "USA"
}
]
}
To be honest, I am totally confused and can't figure out which one is correct and standard style for writing an external .json file (especially those having multiple objects).
So I am asking all my questions here:
- What is the difference between all above formats? Using single quotes, storing the data in a variable or assigning a key to whole data etc.
- How should I compose a correct formatted .json file which can easily be read by JavaScript and PHP?
- In which standard format, the third parties APIs present json data?