On the outermost level, a JSON object starts with a { and end with a }.

Sample data:

{
    "cars": {
        "Nissan": [
            {"model":"Sentra", "doors":4},
            {"model":"Maxima", "doors":4},
            {"model":"Skyline", "doors":2}
        ],
        "Ford": [
            {"model":"Taurus", "doors":4},
            {"model":"Escort", "doors":4}
        ]
    }
}

If the JSON is assigned to a variable called data, then accessing it would be like the following:

data.cars['Nissan'][0].model   // Sentra
data.cars['Nissan'][1].model   // Maxima
data.cars['Nissan'][2].doors   // 2

for (var make in data.cars) {
    for (var i = 0; i < data.cars[make].length; i++) {
        var model = data.cars[make][i].model;
        var doors = data.cars[make][i].doors;
        alert(make + ', ' + model + ', ' + doors);
    }
}

Another approach (using an associative array for car models rather than an indexed array):

{
    "cars": {
        "Nissan": {
            "Sentra": {"doors":4, "transmission":"automatic"},
            "Maxima": {"doors":4, "transmission":"automatic"}
        },
        "Ford": {
            "Taurus": {"doors":4, "transmission":"automatic"},
            "Escort": {"doors":4, "transmission":"automatic"}
        }
    }
}

data.cars['Nissan']['Sentra'].doors   // 4
data.cars['Nissan']['Maxima'].doors   // 4
data.cars['Nissan']['Maxima'].transmission   // automatic

for (var make in data.cars) {
    for (var model in data.cars[make]) {
        var doors = data.cars[make][model].doors;
        alert(make + ', ' + model + ', ' + doors);
    }
}

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:

  • JSON specification
  • JSONLint - The JSON validator
Answer from Matt Coughlin on Stack Overflow
Top answer
1 of 6
188

On the outermost level, a JSON object starts with a { and end with a }.

Sample data:

{
    "cars": {
        "Nissan": [
            {"model":"Sentra", "doors":4},
            {"model":"Maxima", "doors":4},
            {"model":"Skyline", "doors":2}
        ],
        "Ford": [
            {"model":"Taurus", "doors":4},
            {"model":"Escort", "doors":4}
        ]
    }
}

If the JSON is assigned to a variable called data, then accessing it would be like the following:

data.cars['Nissan'][0].model   // Sentra
data.cars['Nissan'][1].model   // Maxima
data.cars['Nissan'][2].doors   // 2

for (var make in data.cars) {
    for (var i = 0; i < data.cars[make].length; i++) {
        var model = data.cars[make][i].model;
        var doors = data.cars[make][i].doors;
        alert(make + ', ' + model + ', ' + doors);
    }
}

Another approach (using an associative array for car models rather than an indexed array):

{
    "cars": {
        "Nissan": {
            "Sentra": {"doors":4, "transmission":"automatic"},
            "Maxima": {"doors":4, "transmission":"automatic"}
        },
        "Ford": {
            "Taurus": {"doors":4, "transmission":"automatic"},
            "Escort": {"doors":4, "transmission":"automatic"}
        }
    }
}

data.cars['Nissan']['Sentra'].doors   // 4
data.cars['Nissan']['Maxima'].doors   // 4
data.cars['Nissan']['Maxima'].transmission   // automatic

for (var make in data.cars) {
    for (var model in data.cars[make]) {
        var doors = data.cars[make][model].doors;
        alert(make + ', ' + model + ', ' + doors);
    }
}

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:

  • JSON specification
  • JSONLint - The JSON validator
2 of 6
23

A good book I'm reading: Professional JavaScript for Web Developers by Nicholas C. Zakas 3rd Edition has the following information regarding JSON Syntax:

"JSON Syntax allows the representation of three types of values".

Regarding the one you're interested in, Arrays it says:

"Arrays are represented in JSON using array literal notation from JavaScript. For example, this is an array in JavaScript:

var values = [25, "hi", true];

You can represent this same array in JSON using a similar syntax:

[25, "hi", true]

Note the absence of a variable or a semicolon. Arrays and objects can be used together to represent more complex collections of data, such as:

{
    "books":
              [
                {
                    "title": "Professional JavaScript",
                    "authors": [
                        "Nicholas C. Zakas"
                    ],
                    "edition": 3,
                    "year": 2011
                },
                {
                    "title": "Professional JavaScript",
                    "authors": [
                        "Nicholas C.Zakas"
                    ],
                    "edition": 2,
                    "year": 2009
                },
                {
                    "title": "Professional Ajax",
                    "authors": [
                        "Nicholas C. Zakas",
                        "Jeremy McPeak",
                        "Joe Fawcett"
                    ],
                    "edition": 2,
                    "year": 2008
                }
              ]
}

This Array contains a number of objects representing books, Each object has several keys, one of which is "authors", which is another array. Objects and arrays are typically top-level parts of a JSON data structure (even though this is not required) and can be used to create a large number of data structures."

To serialize (convert) a JavaScript object into a JSON string you can use the JSON object stringify() method. For the example from Mark Linus answer:

var cars = [{
    color: 'gray',
    model: '1',
    nOfDoors: 4
    },
    {
    color: 'yellow',
    model: '2',
    nOfDoors: 4
}];

cars is now a JavaScript object. To convert it into a JSON object you could do:

var jsonCars = JSON.stringify(cars);

Which yields:

"[{"color":"gray","model":"1","nOfDoors":4},{"color":"yellow","model":"2","nOfDoors":4}]"

To do the opposite, convert a JSON object into a JavaScript object (this is called parsing), you would use the parse() method. Search for those terms if you need more information... or get the book, it has many examples.

🌐
RestfulAPI
restfulapi.net › home › json › json array
JSON Array - Multi-dimensional Array in JSON
November 4, 2023 - Similar to other programming languages, a JSON Array is a list of items surrounded in square brackets ([]).
🌐
W3Schools
w3schools.com › js › js_json_arrays.asp
JSON Arrays
Arrays in JSON are almost the same as arrays in JavaScript.
🌐
JSON Schema
json-schema.org › understanding-json-schema › reference › array
JSON Schema - array
Arrays are used for ordered elements. In JSON, each element in an array may be of a different type.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › what-is-json-array
What is JSON Array? - GeeksforGeeks
July 23, 2025 - JSON array can store values of type string, array, boolean, number, object, or null. In JSON array, values are separated by commas.
🌐
Leapcell
leapcell.io › blog › understanding-json-arrays-of-arrays
Understanding JSON Arrays of Arrays | Leapcell
July 25, 2025 - A JSON array of arrays, also known as a multi-dimensional array, is a structure where each element of the main array is itself an array. This nesting allows for the organization of data in a tabular or matrix-like format.
Find elsewhere
🌐
Javatpoint
javatpoint.com › json-array
JSON Array - javatpoint
JSON Array for beginners and professionals with examples of JSON with java, json array of string, json array of numbers, json array of booleans, json srray of objects, json multidimentional array. Learn JSON array example with object, array, schema, encode, decode, file, date etc.
🌐
ReqBin
reqbin.com › json › uzykkick › json-array-example
What is JSON Array?
Unlike dictionaries, where you can get the value by its key, in a JSON array, the array elements can only be accessed by their index. The following is an example of a JSON array with numbers.
🌐
ArduinoJson
arduinojson.org › version 6 › api › jsonarray
JsonArray | ArduinoJson 6
ArduinoJson 6 user’s manual. A JSON array is an ordered collection of values. A JsonArray is a reference to this array, but a JsonDocument owns the data.
🌐
PTC Community
community.ptc.com › t5 › ThingWorx-Developers › Working-with-JSON-and-Arrays › td-p › 836109
Solved: Working with JSON and Arrays - PTC Community
November 9, 2022 - However if you look closely on the Input parameter, which is a JSON type, it includes the exact same "PlatformData" array as the variable in the code.
🌐
Leapcell
leapcell.io › blog › understanding-json-arrays-a-practical-guide
Understanding JSON Arrays: A Practical Guide | Leapcell
July 25, 2025 - A JSON array is an ordered list of values enclosed in square brackets []. Each value is separated by a comma and can be of any valid JSON data type: string, number, object, array, boolean, or null.
🌐
Oracle
docs.oracle.com › javaee › 7 › api › javax › json › JsonArray.html
JsonArray (Java(TM) EE 7 Specification APIs)
The values in a JsonArray can be of the following types: JsonObject, JsonArray, JsonString, JsonNumber, JsonValue.TRUE, JsonValue.FALSE, and JsonValue.NULL. JsonArray provides various accessor methods to access the values in an array.
🌐
Microsoft Learn
learn.microsoft.com › en-us › sql › t-sql › functions › json-array-transact-sql
JSON_ARRAY (Transact-SQL) - SQL Server | Microsoft Learn
Applies to: SQL Server Azure SQL Database Azure SQL Managed Instance SQL analytics endpoint in Microsoft Fabric Warehouse in Microsoft Fabric · Constructs JSON array text from zero or more expressions.
🌐
CodeUtility
blog.codeutility.io › programming › how-to-use-arrays-in-json-with-examples-in-code-5eeef2665f
How to use Arrays in JSON (With Examples in Code) | CodeUtility
September 26, 2025 - This guide covers how arrays work, how to define them, access them in code, and handle more complex cases like arrays of objects. A JSON array is an ordered list enclosed in square brackets []. It can hold any combination of values, including:
🌐
Processing
processing.org › reference › jsonarray
JSONArray / Reference / Processing.org
String[] species = { "Capra hircus", "Panthera pardus", "Equus zebra" }; String[] names = { "Goat", "Leopard", "Zebra" }; JSONArray values; void setup() { values = new JSONArray(); for (int i = 0; i < species.length; i++) { JSONObject animal = new JSONObject(); animal.setInt("id", i); animal.setString("species", species[i]); animal.setString("name", names[i]); values.setJSONObject(i, animal); } saveJSONArray(values, "data/new.json"); } // Sketch saves the following to a file called "new.json": // [ // { // "id": 0, // "species": "Capra hircus", // "name": "Goat" // }, // { // "id": 1, // "species": "Panthera pardus", // "name": "Leopard" // }, // { // "id": 2, // "species": "Equus zebra", // "name": "Zebra" // } // ]
🌐
Matthew Aisthorpe
matthewaisthorpe.com.au › posts › code › json-object-vs-array
JSON Object vs JSON Array
“What’s the actual difference between a JSON Object and a JSON Array?” · That conversation made me realise that many developers, especially those new to JSON, might have the same question. So, let’s break it down! JSON stands for JavaScript Object Notation, this is a syntax used for storing and exchanging data. Data in JSON can be stored in two primary structures:
🌐
UiPath Community
forum.uipath.com › help › activities
How can i create a Json array from a group of arrays - Activities - UiPath Community Forum
I want to create the below json array from a group of arrays what would be the best way to go about this. i tried a for each loop but it overwrites the first instance. “CompaniesInfo”: [ { “CompanyId”: 138, “CompanyInfo”: { “Score”: “123”, “DocumentKey”: “76149”, “DocumentUrl”: “Test .pdf”, “IsSuccess”: “”, “Comment”: “” } }, { “CompanyId”: 139, “CompanyInfo”: { “Score”: “456”, “DocumentKey”: “76149c7b”, “DocumentUrl”: “Test df”, ...
Published   January 3, 2023