I'll elaborate a bit more on ChrisR awesome answer and bring images from his awesome reference.

A valid JSON always starts with either curly braces { or square brackets [, nothing else.

{ will start an object:

{ "key": value, "another key": value }

Hint: although javascript accepts single quotes ', JSON only takes double ones ".

[ will start an array:

[value, value]

Hint: spaces among elements are always ignored by any JSON parser.

And value is an object, array, string, number, bool or null:

So yeah, ["a", "b"] is a perfectly valid JSON, like you could try on the link Manish pointed.

Here are a few extra valid JSON examples, one per block:

{}

[0]

{"__comment": "json doesn't accept comments and you should not be commenting even in this way", "avoid!": "also, never add more than one key per line, like this"}

[{   "why":null} ]

{
  "not true": [0, false],
  "true": true,
  "not null": [0, 1, false, true, {
    "obj": null
  }, "a string"]
}
Answer from cregox on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_json_server.asp
W3Schools.com
If the file contains a JSON array, response.json() returns a JavaScript array.
๐ŸŒ
JSON Schema
json-schema.org โ€บ understanding-json-schema โ€บ reference โ€บ array
JSON Schema - array
Tuple validation is useful when the array is a collection of items where each has a different schema and the ordinal index of each item is meaningful. For example, you may represent a street address such as 1600 Pennsylvania Avenue NW as a 4-tuple of the form:
๐ŸŒ
CodeSignal
codesignal.com โ€บ learn โ€บ courses โ€บ parsing-json-with-csharp โ€บ lessons โ€บ parsing-json-arrays-and-nested-structures
Parsing JSON Arrays and Nested Structures
Similarly to parsing simple JSON arrays, we can handle nested structures where arrays contain further arrays or objects. This nesting adds complexity but allows for a richer and more detailed representation of data. Take a look at the nested employee lists in each department from data.json:
๐ŸŒ
Codeblogmoney
codeblogmoney.com โ€บ json-example-with-data-types-including-json-array
JSON Example with Data Types Including JSON Array
July 3, 2018 - JSON Example This article will have all the JSON Examples which covers each and every data type JSON supports. Here is the list of JSON data types. Valid JSON Data Types String Number Object Array Boolean Null 1. JSON String Example: 1 2 3 4 5 { "firstname": "Tom", "lastname": "Cruise", "occupation": "Actor" } This example shows information about a person, and you know Tom Cruise.
Find elsewhere
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 - Each item in the array is separated by a comma. ... Similar to other programming languages, a JSON Array is a list of items surrounded in square brackets ([]).
๐ŸŒ
Medium
medium.com โ€บ @harshadawayal4949 โ€บ json-array-json-object-6ea512b1f66c
JSON Array & JSON Object | by Harshada Wayal | Medium
March 22, 2024 - Values in JSON array are indexed stating from 0. ... A JSON object is an unordered collection of key-value pairs enclosed within curly braces โ€˜{ }โ€™. Each key in JSON object must be a string, and it must be unique within that object. The values associated with keys in a JSON object can be of any valid JSON data type - ... An example here is Student object.
๐ŸŒ
YouTube
youtube.com โ€บ watch
07 Arrays in JSON โ€“ Representing ordered lists of values - YouTube
"=Introduce yourself to arrays in JSON. Learn to represent ordered lists of values, a crucial concept for organizing and managing data in JSON.https://github...
Published: December 31, 2023
๐ŸŒ
JSON for Modern C++
json.nlohmann.me โ€บ api โ€บ basic_json โ€บ array
array - JSON for Modern C++
#include <iostream> #include ... create JSON arrays json j_no_init_list = json::array(); json j_empty_init_list = json::array({}); json j_nonempty_init_list = json::array({1, 2, 3, 4}); json j_list_of_pairs = json::array({ {"one", 1}, {"two", 2} }); // serialize the JSON ...
๐ŸŒ
Qlik Community
community.qlik.com โ€บ t5 โ€บ Member-Articles โ€บ Parsing-JSON-Array-Homogeneous-Objects โ€บ ta-p โ€บ 2535153
Parsing: JSON Array (Homogeneous Objects) - Qlik Community - 2535153
November 4, 2025 - The image depicts what is called a JSON Array and to be precise its a JSON Array of Homogeneous Objects. I'm sure you are no greenhorn at this point in my series on parsing JSON. If I said tell me the name who is the owner of the third saloon in our town, I'm sure you would immediately reply "Miss...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ what-is-json-array
What is JSON Array? - GeeksforGeeks
July 23, 2025 - JSON array of Strings contains string elements only. For example, the array below has 6 string elements, "Ram", "Shyam", "Radhika", "Akshay", "Prashant" and "Varun", each element is separated with a comma (,).
Top answer
1 of 7
3

Lean towards option 1, as it's a more expected format.

Option 1 works with JSON as it's designed to be used and therefore benefits from what JSON offers (a degree of human readability, which is good for debugging, and straightforward parsing, which is good for limiting entire categories of bugs to begin with).

Option 2 begrudgingly adopts JSON and subverts many of the benefits. If you don't want human readability, use protobuf or something similar... AIWalker's "CSV"-like approach isn't terrible either. It is marginally better (readable) than splitting objects apart and recombining them. But, this is still not as good (readable) as using JSON "as designed".

Also bear in mind, your API responses are also likely going to be gzipped. Most of the repetition in option 1 will be quickly and transparently condensed over the wire.

As an aside, if you're moving a lot of data, also consider JSONL or paginated results. Pagination can be especially helpful for web clients, as it places natural pauses in the processing, providing a degree of "organic" protection against UI lockups.

2 of 7
3

A list of objects is easier to work with. You can use append, map, filter... All the nice things JS Arrays have which manual indexing doesn't. And there's no way to get out of sync, so that's an entire class of bugs gone.

If you're worried about efficiency:

  • Measure (premature optimization is the root of all evil)
  • Consider the list of lists trick AIWalker proposed
  • Consider an outright binary format
  • Make sure gzip is enabled
  • Measure (it's worth saying twice)
๐ŸŒ
JSONata
docs.jsonata.org โ€บ simple
Simple Queries ยท JSONata
Here are some example expressions and their results when applied to the above JSON document: ... Path not found. Returns nothing (i.e. Javascript undefined) ... JSON arrays are used when an ordered collection of values is required. Each value in the array is associated with an index (position) ...
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ dotnet โ€บ core โ€บ tools โ€บ test-prerelease-sdk-locally
Test prerelease .NET SDKs locally with global.json paths - .NET CLI | Microsoft Learn
April 9, 2026 - The host version is not the same as the SDK version reported by dotnet --version. If the host shows an older version (for example, 8.0.x or 9.0.x), install .NET 10+ system-wide to update the dotnet host on your PATH. The sdk.paths property is a JSON array of folder paths where the .NET host looks for SDK installations.
๐ŸŒ
n8n
community.n8n.io โ€บ questions
A 'json' property isn't an object - Questions - n8n Community
April 9, 2026 - Hi. Iโ€™m getting the same error that was covered here: Returning a array from Code Node - A 'json' property isn't an object โ€“ but Iโ€™m not sure how to resolve it in this instance Describe the problem/error/question Iโ€™m geโ€ฆ
๐ŸŒ
Robotastemtraining
robotastemtraining.com โ€บ read โ€บ how-do-you-add-elements-to-a-json-array
How do you add elements to a JSON Array?
To add elements to a JSON array in JavaScript, you can use the array methods such as push() or concat(). Below are some examples: