This isn't a single JSON object. You have an array of JSON objects. You need to loop over array first and then access each object. Maybe the following kickoff example is helpful:

var arrayOfObjects = [{
  "id": 28,
  "Title": "Sweden"
}, {
  "id": 56,
  "Title": "USA"
}, {
  "id": 89,
  "Title": "England"
}];

for (var i = 0; i < arrayOfObjects.length; i++) {
  var object = arrayOfObjects[i];
  for (var property in object) {
    alert('item ' + i + ': ' + property + '=' + object[property]);
  }
  // If property names are known beforehand, you can also just do e.g.
  // alert(object.id + ',' + object.Title);
}

If the array of JSON objects is actually passed in as a plain vanilla string, then you would indeed need eval() here.

var string = '[{"id":28,"Title":"Sweden"}, {"id":56,"Title":"USA"}, {"id":89,"Title":"England"}]';
var arrayOfObjects = eval(string);
// ...

To learn more about JSON, check MDN web docs: Working with JSON .

Answer from BalusC on Stack Overflow
🌐
Adobe
opensource.adobe.com › Spry › samples › data_region › JSONDataSetSample.html
JSON Data Set Sample
Notice that the names of the columns ... the flattening process, you simply pass an array of strings: var dsExample7 = new Spry.Data.JSONDataSet("../../data/json/object-03.js", { subPaths: [ "image", "thumbnail" ] }); ......
🌐
JSON Schema
json-schema.org › learn › miscellaneous-examples
JSON Schema - Miscellaneous Examples
The fruits property contains an array of strings, while the vegetables property contains an array of objects, each adhering to the "veggie" schema definition. This example introduces the enum validation keyword which is used with an array of values that includes an integer (42), a boolean (true), a string ("hello"), null, and an array ([1, 2, 3]).
🌐
GitHub
gist.github.com › fatihacet › 4247503
Sample array of object json · GitHub
Sample array of object json. GitHub Gist: instantly share code, notes, and snippets.
🌐
W3Schools
w3schools.com › js › js_json_arrays.asp
JSON Arrays
AJAX Intro AJAX XMLHttp AJAX Request AJAX Response AJAX XML File AJAX PHP AJAX ASP AJAX Database AJAX Applications AJAX Examples JS JSON · JSON Intro JSON Syntax JSON vs XML JSON Data Types JSON Parse JSON Stringify JSON Objects JSON Arrays JSON Server JSON PHP JSON HTML JSON JSONP JS jQuery
🌐
Codeblogmoney
codeblogmoney.com › json-example-with-data-types-including-json-array
JSON Example with Data Types Including JSON Array
July 3, 2018 - 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.
🌐
JSON Editor Online
jsoneditoronline.org › home › datasets › json-file-example
Exploring the power of JSON: a real-life JSON file example collection
July 25, 2023 - You can check them out to understand what a JSON file should look like and how to write a JSON file yourself. You can also use them if you need some example data for testing or debugging. There are some large files included to be able to do performance tests for example. Here is a basic JSON example. It is an object with three properties: a name, age, and city.
🌐
W3Schools
w3schools.io › file › json-cheatsheet
JSON cheatsheet complete tutorial with examples - w3schools
... The object contains key and value pairs and the Array contains a group of objects enclosed in a square bracket[]. { "roles": [ {"name": "admin", "id": 1`}, {"name": "sales", "id": 2} ] } Two-dimensional arrays are an array of arrays.
Find elsewhere
🌐
IBM
ibm.com › docs › en › datapower-gateway › 10.6.0
JSON examples
JSON objects and arrays can be transformed with transform actions. The following examples and the examples in the related topics, provide sample JSON objects and arrays and transformations of those objects and arrays. These examples demonstrate some JSON message processing that the DataPower ...
🌐
Stack Overflow
stackoverflow.com › questions › 24887490 › how-to-read-json-file-array-form-using-simple-json-library
java - How to read json file (array form) using simple JSON library? - Stack Overflow
JSONArray records = (JSONArray)a.get("records"); for (Object o : records) { JSONObject person = (JSONObject) o; String name = (String) person.get("name"); System.out.println(name); String city = (String) person.get("city"); System.out.println(city); ...
🌐
JSONata
docs.jsonata.org › simple
Simple Queries · JSONata
To support the extraction of values from a JSON structure, a location path syntax is defined. In common with XPath, this will select all possible values in the document that match the specified location path. The two structural constructs of JSON are objects and arrays.
🌐
Micro Focus
microfocus.com › documentation › silk-performer › 205 › en › silkperformer-205-webhelp-en › GUID-0847DE13-2A2F-44F2-A6E7-214CD703BF84.html
JSON Array Structure
In contrast to regular arrays from the BDL, the elements of a JSON array can be of different data types. The following data types are allowed for JSON arrays: [ ] //Empty JSON array [ 0, 1, 2, 3, 4, 5] [ “StringValue”, 10, 20.13, true, null ] [ { “Name” : “Nested Object” }, [ 10, 20, true, 40, “Nested Array” ] ]
🌐
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.
🌐
RestfulAPI
restfulapi.net › home › json › json array
JSON Array - Multi-dimensional Array in JSON
November 4, 2023 - It is known as an array of arrays or a multi-dimensional JSON array. var siteInfo = { "name" : "blogger", "users" : [ [ "admins", "1", "2" , "3"], [ "editors", "4", "5" , "6"], ] } A simple for loop to iterate over a multi-dimensional array ...
🌐
Gastonsanchez
gastonsanchez.com › intro2cwd › json.html
42 JSON Data | Introduction to Computing With Data
By using a simple syntax, you can ... a string of plain text. As you will see, you can also nest arrays and objects, allowing you to create complex data structures. Let’s first talk about what JSON is and why is important. JSON is a data representation format very similar to XML. It’s used widely across the internet for almost every single API that you will access as well as for config files and things ...
🌐
JSON Schema
json-schema.org › understanding-json-schema › reference › array
JSON Schema - array
Just as unevaluatedProperties affects ... in an object, unevaluatedItems affects only items in an array. Watch out! The word "unevaluated" does not mean "not evaluated by items, prefixItems, or contains." "Unevaluated" means "not successfully evaluated", or "does not evaluate to true". Like with items, if ...
🌐
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; } } }
🌐
ReqBin
reqbin.com › json › uzykkick › json-array-example
What is JSON Array?
The following is an example of an array of JSON booleans: ... A JSON object is similar to a JavaScript object. We can also create a JSON array containing many objects, and then we can iterate over this array or use "[]" square brackets to get the desired object.
🌐
UiPath Community
forum.uipath.com › help › studio
JSON Array with multiple json objects and json arrays - Studio - UiPath Community Forum
September 25, 2021 - hello, I made an API call and I got a json response. I deserialized the json response, so that I have a json object. Now I want to extract some information from the object, but I have not managed to do it. Here is my json response: { “results”: [ { “group”: { “mediaType”: “chat”, “queueId”: “7a982920-3a-4083-8315-db0f5fec6c44” }, “data”: [ { “interval”: “2021-08-16T00:00:00.000Z/2021-08-22T00:00:00.000Z”, “metrics”: [ { “metric”: “tAcw”, “stats”: { “max”: 800000, “min”: 6000, ...