I’ve never used JSON before so I’m not familiar with its syntax.
At the moment I have multiple arrays containing different pieces of data.
I would like to create one JSON object, that contains the multiple arrays each with several pieces of data.
E.g.
An object called cars, containing multiple arrays each for a different make of car. In each array would be the model of car along with some other types of data e.g. number of doors (doesn’t really matter its just a fictional example.)
It would be greatly appreciated if someone explained the syntax with an example.
On the outermost level, a JSON object starts with a
{and end with a}.Sample data:
If the JSON is assigned to a variable called data, then accessing it would be like the following:
Another approach (using an associative array for car models rather than an indexed array):
Edit:
Correction: A JSON object starts with
{and ends with}, but it’s also valid to have a JSON array (on the outermost level), that starts with[and ends with].Also, significant syntax errors in the original JSON data have been corrected: All key names in a JSON object must be in double quotes, and all string values in a JSON object or a JSON array must be in double quotes as well.
See: