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 - JSON Array is a list of items surrounded by square brackets. Each item in the array is separated by a comma. Learn about multi-dimensional arrays.
Discussions

How can i create a Json array from a group of arrays
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”, ... More on forum.uipath.com
🌐 forum.uipath.com
0
January 5, 2023
Creating Arrays from JSON properties and arrays
I have been wracking my brain trying to figure out how to include a could of JSON property that is outside of a nested JSON array that contains information that I need to include in a MS Teams response. What I am doing: I am using the Cisco Umbrella plugin to search Umbrella activity for users ... More on discuss.rapid7.com
🌐 discuss.rapid7.com
0
November 21, 2024
Objects in Arrays passed as a JSON body
I’m sure this is just a syntax issue somewhere on my end, or I’m not understanding the console output. I have this script that will read through an array of objects: let mzs = pm.collectionVariables.get(“mzs”); if(!mzs || mzs.length == 0) { mzs =[{“id”: “test1”, “email”: ... More on community.postman.com
🌐 community.postman.com
0
August 23, 2024
Create JSON with Arrays of different types?
Let's go a bit out of order: Does indentation matter in JSON? No. The only things that matter in JSON are the few symbols it uses, it ignores whitespace outside of strings. But also: I don't know how to format it to have every variable listed in the correct spot. Order does not matter in JSON. That's why every property has a name. For the rest of it, here's a quick crash course. You didn't say how you're "making a JSON file". Usually in C# these days, we use a "serialization library". MS has one in I think the System.Text namespace, but before that existed everyone used a package called Newtonsoft.JSON. They both work roughly the same: they convert C# objects to and from JSON. So if I wrote a class like this: public class Example { public int Value { get; set; } } I'd write code (sort of, I'm not double-checking) like this with Newtonsoft: var example = new Example(); example.Value = 10; var json = JsonConvert.SerializeObject(example); The JSON I'd get in return would look like: { "Value": 10 } These libraries support a lot of types by default. We can go backwards from JSON back to C#. Suppose I saw JSON like this: { "examples": [ { "Value": 10 } ] } Think about it by reading from top to bottom. This is: An object with properties: "examples", an array of objects that have these properties: "Value", an integer I see two objects in the definitions, so I need to write two classes: // "an object with an 'examples' property" // Note the name DOES NOT MATTER, because JSON objects do not have type names. public class Examples { // "an array of objects" // Note I can use a capital letter even though the JSON used lowercase, the serializer // is smart enough to handle that. public Example[] Examples { get; set; } } // "an object with a 'Value' property" public class Example { public int Value { get; set; } } The important thing to note is the serializer is smart enough to see that since Examples has an array of Example, it should try to parse the "inner" objects to fit the Example class. My second example intentionally looks a lot like your JSON. You have an object with an "APInvoices" property that is an array of other objects. THOSE objects have many properties, including some like "Images" that are arrays of OTHER objects. To serialize/deserialize your JSON, you're going to need to write 7 or 8 total C# classes. More on reddit.com
🌐 r/csharp
7
2
October 13, 2022
🌐
W3Schools
w3schools.com › js › js_json_arrays.asp
JSON Arrays
Arrays in JSON are almost the same as arrays in JavaScript.
🌐
Leapcell
leapcell.io › blog › understanding-json-arrays-of-arrays
Understanding JSON Arrays of Arrays | Leapcell
July 25, 2025 - This nesting allows for the organization of data in a tabular or matrix-like format. ... In this example, the matrix key holds an array containing three arrays, each representing a row in the matrix. JSON arrays of arrays are particularly useful in scenarios such as:
🌐
CodeSignal
codesignal.com › learn › courses › parsing-json-with-csharp › lessons › parsing-json-arrays-and-nested-structures
Parsing JSON Arrays and Nested Structures
Similarly, each department contains another array called employees. To parse this nested structure, we use a nested loop approach, where the outer loop processes the departments and the inner loop traverses through each employee within those departments: This method allows us to handle potential null values effectively, ensuring that we can navigate complex JSON structures seamlessly and extract the necessary information from each level of nesting.
🌐
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 5, 2023
Find elsewhere
🌐
Rapid7 Discuss
discuss.rapid7.com › insightconnect
Creating Arrays from JSON properties and arrays - InsightConnect - Rapid7 Discuss
November 21, 2024 - I have been wracking my brain trying to figure out how to include a could of JSON property that is outside of a nested JSON array that contains information that I need to include in a MS Teams response. What I am doing: I am using the Cisco Umbrella plugin to search Umbrella activity for users ...
🌐
JSON Schema
json-schema.org › understanding-json-schema › reference › array
JSON Schema - array
For example, you may represent a street address such as 1600 Pennsylvania Avenue NW as a 4-tuple of the form: ... To do this, we use the prefixItems keyword. prefixItems is an array, where each item is a schema that corresponds to each index of the document's array.
🌐
Postman
community.postman.com › help hub
Objects in Arrays passed as a JSON body - Help Hub - Postman Community
August 23, 2024 - I’m sure this is just a syntax issue somewhere on my end, or I’m not understanding the console output. I have this script that will read through an array of objects: let mzs = pm.collectionVariables.get(“mzs”); if(!mzs || mzs.length == 0) { mzs =[{“id”: “test1”, “email”: ...
🌐
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.
🌐
Reddit
reddit.com › r/csharp › create json with arrays of different types?
r/csharp on Reddit: Create JSON with Arrays of different types?
October 13, 2022 -

I am trying to make a JSON file using C#, and to make a simple one seems pretty easy. but on thing I am struggling with is an array. The entire file falls inside an array, and I can't seem to find documentation enough to make that happen though. Does anyone know how to do this?

Below I posted a link to an example of a JSON I would be interested in making. I created an object in C# that has every variable listed, but I don't know how to format it to have every variable listed in the correct spot. I appreciate any help. Thank you!

https://help.viewpoint.com/en/spectrum/spectrum/api-web-services/api-web-services/list-of-web-services/accounts-payable-services/vendor-invoice-multi-line

Edit: Does indentation matter in JSON? I suppose I could just hardcore a massive string and insert the variables as needed if that’s that case

Top answer
1 of 2
2
Let's go a bit out of order: Does indentation matter in JSON? No. The only things that matter in JSON are the few symbols it uses, it ignores whitespace outside of strings. But also: I don't know how to format it to have every variable listed in the correct spot. Order does not matter in JSON. That's why every property has a name. For the rest of it, here's a quick crash course. You didn't say how you're "making a JSON file". Usually in C# these days, we use a "serialization library". MS has one in I think the System.Text namespace, but before that existed everyone used a package called Newtonsoft.JSON. They both work roughly the same: they convert C# objects to and from JSON. So if I wrote a class like this: public class Example { public int Value { get; set; } } I'd write code (sort of, I'm not double-checking) like this with Newtonsoft: var example = new Example(); example.Value = 10; var json = JsonConvert.SerializeObject(example); The JSON I'd get in return would look like: { "Value": 10 } These libraries support a lot of types by default. We can go backwards from JSON back to C#. Suppose I saw JSON like this: { "examples": [ { "Value": 10 } ] } Think about it by reading from top to bottom. This is: An object with properties: "examples", an array of objects that have these properties: "Value", an integer I see two objects in the definitions, so I need to write two classes: // "an object with an 'examples' property" // Note the name DOES NOT MATTER, because JSON objects do not have type names. public class Examples { // "an array of objects" // Note I can use a capital letter even though the JSON used lowercase, the serializer // is smart enough to handle that. public Example[] Examples { get; set; } } // "an object with a 'Value' property" public class Example { public int Value { get; set; } } The important thing to note is the serializer is smart enough to see that since Examples has an array of Example, it should try to parse the "inner" objects to fit the Example class. My second example intentionally looks a lot like your JSON. You have an object with an "APInvoices" property that is an array of other objects. THOSE objects have many properties, including some like "Images" that are arrays of OTHER objects. To serialize/deserialize your JSON, you're going to need to write 7 or 8 total C# classes.
2 of 2
1
As u/Slypenslyde mentioned, List get serialized to a JSON array in both Newtonsoft.Json and System.Text.Json so may be easier to handle than an array in some situations. You can also use annotations to map a property in JSON to a C# compliant name. using System; using System.Collections.Generic; using System.Text.Json; using System.Text.Json.Serialization; public class Program { public static void Main() { var root = new Root(); int idCnt = 0; // *** ignore this block, just to populate some fake invoices *** for (int i = 0; i < 10; i++) { var invoice = new Invoice() { InvoiceNumber = $"INV{(i + 1).ToString().PadLeft(5, '0')}", VendorCode = $"V{((i % 2) + 1).ToString().PadLeft(5, '0')}", }; int lineCnt = ((i % 2) + 1) * 4; for (int j = 0; j < lineCnt; j++) { idCnt++; invoice.ApInvoiceDetails.Add(new InvoiceLine() { ItemCode = $"PRD{((idCnt % 3) + 1).ToString().PadLeft(5, '0')}", ItemDescription = $"Some product we sell {((idCnt % 3) + 1)}", Quantity = ((j % 4) + 1), Amount = ((j % 3) + 1) * 5 }); } root.ApInvoices.Add(invoice); } // *** end ignore *** // serialize to json string string json = JsonSerializer.Serialize(root); Console.WriteLine(json); // deserialize for json string var newRoot = JsonSerializer.Deserialize(json); Console.WriteLine($"First invoice no: {newRoot.ApInvoices[0].InvoiceNumber}"); } private class Root { [JsonPropertyName("APInvoices")] public List ApInvoices { get; set; } = new(); } private class Invoice { [JsonPropertyName("Vendor_Code")] public string VendorCode { get; set; } [JsonPropertyName("Invoice_Number")] public string InvoiceNumber { get; set; } [JsonPropertyName("APInvoiceDetails")] public List ApInvoiceDetails { get; set; } = new(); } private class InvoiceLine { [JsonPropertyName("Item_Code")] public string ItemCode { get; set; } [JsonPropertyName("Item_Description")] public string ItemDescription { get; set; } public decimal Quantity { get; set; } public decimal Amount { get; set; } } }
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array
Array - JavaScript | MDN
2 weeks ago - The Array object, as with arrays in other programming languages, enables storing a collection of multiple items under a single variable name, and has members for performing common array operations.
🌐
Medium
medium.com › @apdharshi › difference-between-arrays-and-json-objects-fa1c8598f9f1
Difference between Arrays and JSON Objects | by APD | Medium
May 19, 2019 - These can be otherwise called as multi-dimensional arrays. [ [1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7]]; ... An object is a collection of properties, ...
🌐
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:
🌐
OpenAI Developer Community
community.openai.com › api
`json_mode` returns no JSON arrays - API - OpenAI Developer Community
November 8, 2023 - Setting response_format to { type: "json_object" } seems only returns singular {"key1": "value1", "key2": "value2", ...} JSON object than array like [{"key1": "value1", "key2": "value2"}, {"key1": "value3", "key2": "value4"}, ...], unless the array is encapsulated as a value within a key-value pair.
🌐
JAXB
javaee.github.io › tutorial › jsonp001.html
Introduction to JSON
Arrays are enclosed in brackets ([]), and their values are separated by a comma (,). Each value in an array may be of a different type, including another array or an object. When objects and arrays contain other objects or arrays, the data has a tree-like structure. JSON is often used as a common format to serialize and deserialize data in applications that communicate with each other over the Internet.
🌐
PrepBytes
prepbytes.com › home › arrays › json array: structure and example
JSON Array: Structure and Example
September 22, 2023 - The array below, for instance, contains 5 entries, each of which is either true or false. ... JSON Array Example: Here, the key boolean in the jsonBooleanArray object is assigned a JSON Array of Booleans.
🌐
ReqBin
reqbin.com › json › uzykkick › json-array-example
What is JSON Array?
June 11, 2022 - Arrays in JSON are used to store a list of primitive or complex objects. JSON arrays can store different types of elements: strings, numbers, booleans, objects, and multidimensional arrays.