You don't need to use arrays.

JSON values can be arrays, objects, or primitives (numbers or strings).

You can write JSON like this:

{ 
    "stuff": {
        "onetype": [
            {"id":1,"name":"John Doe"},
            {"id":2,"name":"Don Joeh"}
        ],
        "othertype": {"id":2,"company":"ACME"}
    }, 
    "otherstuff": {
        "thing": [[1,42],[2,2]]
     }
}

You can use it like this:

obj.stuff.onetype[0].id
obj.stuff.othertype.id
obj.otherstuff.thing[0][1]  //thing is a nested array or a 2-by-2 matrix.
                            //I'm not sure whether you intended to do that.
Answer from SLaks on Stack Overflow
Top answer
1 of 5
25

The first code is an example of Javascript code, which is similar, however not JSON. JSON would not have 1) comments and 2) the var keyword

You don't have any comments in your JSON, but you should remove the var and start like this:

orders: {

The [{}] notation means "object in an array" and is not what you need everywhere. It is not an error, but it's too complicated for some purposes. AssociatedDrug should work well as an object:

"associatedDrug": {
                "name":"asprin",
                "dose":"",
                "strength":"500 mg"
          }

Also, the empty object labs should be filled with something.

Other than that, your code is okay. You can either paste it into javascript, or use the JSON.parse() method, or any other parsing method (please don't use eval)

Update 2 answered:

obj.problems[0].Diabetes[0].medications[0].medicationsClasses[0].className[0].associatedDrug[0].name

returns 'aspirin'. It is however better suited for foreaches everywhere

2 of 5
19

I successfully solved my problem. Here is my code:

The complex JSON object:

   {
    "medications":[{
            "aceInhibitors":[{
                "name":"lisinopril",
                "strength":"10 mg Tab",
                "dose":"1 tab",
                "route":"PO",
                "sig":"daily",
                "pillCount":"#90",
                "refills":"Refill 3"
            }],
            "antianginal":[{
                "name":"nitroglycerin",
                "strength":"0.4 mg Sublingual Tab",
                "dose":"1 tab",
                "route":"SL",
                "sig":"q15min PRN",
                "pillCount":"#30",
                "refills":"Refill 1"
            }],
            "anticoagulants":[{
                "name":"warfarin sodium",
                "strength":"3 mg Tab",
                "dose":"1 tab",
                "route":"PO",
                "sig":"daily",
                "pillCount":"#90",
                "refills":"Refill 3"
            }],
            "betaBlocker":[{
                "name":"metoprolol tartrate",
                "strength":"25 mg Tab",
                "dose":"1 tab",
                "route":"PO",
                "sig":"daily",
                "pillCount":"#90",
                "refills":"Refill 3"
            }],
            "diuretic":[{
                "name":"furosemide",
                "strength":"40 mg Tab",
                "dose":"1 tab",
                "route":"PO",
                "sig":"daily",
                "pillCount":"#90",
                "refills":"Refill 3"
            }],
            "mineral":[{
                "name":"potassium chloride ER",
                "strength":"10 mEq Tab",
                "dose":"1 tab",
                "route":"PO",
                "sig":"daily",
                "pillCount":"#90",
                "refills":"Refill 3"
            }]
        }
    ],
    "labs":[{
        "name":"Arterial Blood Gas",
        "time":"Today",
        "location":"Main Hospital Lab"      
        },
        {
        "name":"BMP",
        "time":"Today",
        "location":"Primary Care Clinic"    
        },
        {
        "name":"BNP",
        "time":"3 Weeks",
        "location":"Primary Care Clinic"    
        },
        {
        "name":"BUN",
        "time":"1 Year",
        "location":"Primary Care Clinic"    
        },
        {
        "name":"Cardiac Enzymes",
        "time":"Today",
        "location":"Primary Care Clinic"    
        },
        {
        "name":"CBC",
        "time":"1 Year",
        "location":"Primary Care Clinic"    
        },
        {
        "name":"Creatinine",
        "time":"1 Year",
        "location":"Main Hospital Lab"  
        },
        {
        "name":"Electrolyte Panel",
        "time":"1 Year",
        "location":"Primary Care Clinic"    
        },
        {
        "name":"Glucose",
        "time":"1 Year",
        "location":"Main Hospital Lab"  
        },
        {
        "name":"PT/INR",
        "time":"3 Weeks",
        "location":"Primary Care Clinic"    
        },
        {
        "name":"PTT",
        "time":"3 Weeks",
        "location":"Coumadin Clinic"    
        },
        {
        "name":"TSH",
        "time":"1 Year",
        "location":"Primary Care Clinic"    
        }
    ],
    "imaging":[{
        "name":"Chest X-Ray",
        "time":"Today",
        "location":"Main Hospital Radiology"    
        },
        {
        "name":"Chest X-Ray",
        "time":"Today",
        "location":"Main Hospital Radiology"    
        },
        {
        "name":"Chest X-Ray",
        "time":"Today",
        "location":"Main Hospital Radiology"    
        }
    ]
}

The jQuery code to grab the data and display it on my webpage:

$(document).ready(function() {
var items = [];

$.getJSON('labOrders.json', function(json) {
  $.each(json.medications, function(index, orders) {
    $.each(this, function() {
        $.each(this, function() {
            items.push('<div class="row">'+this.name+"\t"+this.strength+"\t"+this.dose+"\t"+this.route+"\t"+this.sig+"\t"+this.pillCount+"\t"+this.refills+'</div>'+"\n");
        });
    });
  });

  $('<div>', {
    "class":'loaded',
    html:items.join('')
  }).appendTo("body");

});

});

Discussions

Nested JSON Array of Arrays
I am trying to read the following JSON structure to a Dictionary object and conversely create JSON from a Dictionary object containing a list of lists, i.e. the More on community.appian.com
🌐 community.appian.com
0
0
December 2, 2017
How can I access a nested array within a JSON file?
To access a nested array within a JSON file, you can traverse the JSON structure using the array index notation. For example, let’s say your JSON data resembles this structure: {"data": [["apple", "banana"], ["car", "bike"]]}. To retrieve the item “car”, you’d navigate using data[1][0]. ... More on community.latenode.com
🌐 community.latenode.com
0
0
October 29, 2024
JSON object to array of nested JSON
I have a JSON object in cosmos DB(source) which I need to transform into an array of nested JSON objects(similar to source objects)in Cosmos DB(sink). Using the derived column I am facing an error during typecast of complex json to array. Could I get an… More on learn.microsoft.com
🌐 learn.microsoft.com
1
0
Create a nested JSON based on an array of JSON objects
James, The folder names are just for reference. George, What I mean is I have an array of JSON objects. I am new to this, so pardon my errors. ... You could use a nested hash table as reference to the same directories and build in the same way the result set. More on stackoverflow.com
🌐 stackoverflow.com
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-access-and-process-nested-objects-arrays-or-json
How to Access and Process Nested Objects, Arrays, or JSON? - GeeksforGeeks
Recursive functions allow you to access and process deeply nested objects or arrays by repeatedly calling the function on nested items. This is helpful when we don't know the exact length of the object. ... const o1 = { o2: { name: "Sourav", contacts: { emails: ["sourav@example.com", "sourav.work@example.com"], phone: "123-456-7890" } } }; function printNested(obj) { if (typeof obj === 'object') { for (let key in obj) { printNested(obj[key]); } } else { console.log(obj); } } printNested(o1); ... For JSON data, you can use JSON.parse() to convert JSON strings into JavaScript objects and JSON.stringify() to convert JavaScript objects into JSON strings.
Published   July 23, 2025
🌐
Workiva
support.workiva.com › hc › en-us › articles › 19581207597460-CLP-JSON-Array-of-Nested-Objects
CLP - JSON Array of Nested Objects – Support Center
July 10, 2024 - Enter variety for the Column Name and .name for the JSONPath parameters. Select Pipe for the Delimiter parameter. ... As noted, the dataset has an array (i.e., multiple items) of nested objects. To process each of the varieties individually, row numbers must be added to the dataset.
🌐
ArduinoJson
arduinojson.org › version 5 › faq › how to create complex nested objects?
How to create complex nested objects? | ArduinoJson 5
1 week ago - Bag of Tricks · Pitfalls · Release notes · Upgrade guide · To create a nested object, call createNestedObject(). To create a nested array, call createNestedArray(). For example: DynamicJsonBuffer jsonBuffer; JsonObject& root = ...
🌐
Liquid-technologies
blog.liquid-technologies.com › advanced-data-structures-in-json-part-3-of-4
Advanced Data Structures in JSON: Nested Objects & Arrays
July 4, 2025 - Visualizing these nested structures is key, and tools like the graphical JSON viewer in Liquid Studio JSON Editor can be invaluable for navigating and understanding complex hierarchies. Often, you need to represent a list or collection of items, where each item is itself a complex entity with multiple attributes. This is achieved using an array of objects.
🌐
CodeSignal
codesignal.com › learn › courses › parsing-json-with-csharp › lessons › parsing-json-arrays-and-nested-structures
Parsing JSON Arrays and Nested Structures
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: 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:
Find elsewhere
🌐
Micro Focus
microfocus.com › documentation › silk-performer › 205 › en › silkperformer-205-webhelp-en › GUID-2CC23B7F-8C73-414F-A82D-E386B1F3F9F9.html
Receiving Nested JSON Objects and JSON Arrays
The only difference is that they return specified elements from a JSON array instead of properties from a JSON object. dcltrans transaction TMain var jsonParentString : string; jsonParent : number; jsonArray : number; jsonObject : number; begin jsonParentString := "[" "{" "\"Name\": \"Nested ...
🌐
Lokalise
docs.lokalise.com › all collections › keys and files › supported file formats › json nested (.json)
JSON nested (.json) | Lokalise Help Center: Documentation and helpful resources
Unlike flat JSON files, nested JSON files can contain objects within objects, allowing for a deeper hierarchical organization of translation strings.
🌐
Example Code
example-code.com › java › json_nested_array.asp
Java JSON: Nested Array
Chilkat • HOME • Android™ • AutoIt • C • C# • C++ • Chilkat2-Python • CkPython • Classic ASP • DataFlex • Delphi DLL • Go • Java • Node.js • Objective-C • PHP Extension • Perl • PowerBuilder • PowerShell • PureBasic • Ruby • SQL Server • Swift • Tcl • Unicode C • Unicode C++ • VB.NET • VBScript • Visual Basic 6.0 • Visual FoxPro • Xojo Plugin
🌐
Appian Community
community.appian.com › discussions › f › general › 11487 › nested-json-array-of-arrays
Nested JSON Array of Arrays
December 2, 2017 - I am trying to read the following JSON structure to a Dictionary object and conversely create JSON from a Dictionary object containing a list of lists, i.e. the
🌐
Latenode
community.latenode.com › other questions › javascript
How can I access a nested array within a JSON file?
October 29, 2024 - To access a nested array within a JSON file, you can traverse the JSON structure using the array index notation. For example, let’s say your JSON data resembles this structure: {"data": [["apple", "banana"], ["car", "bike"]]}. To retrieve ...
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 153749 › json-object-to-array-of-nested-json
JSON object to array of nested JSON - Microsoft Q&A
Thanks Himanshu for your attention. My issue is now resolved. I used hierarchy to create an array out of my jSON inputs which resolved the issue.
🌐
DEV Community
dev.to › iamcymentho › demystifying-nested-data-a-guide-to-accessing-and-processing-objects-arrays-and-json-in-javascript-34im
Demystifying Nested Data: A Guide to Accessing and Processing Objects, Arrays, and JSON in JavaScript - DEV Community
September 15, 2023 - This section covers the basics of working with JSON data. ... In JavaScript, you can parse JSONdata from a string into a JavaScript object using the JSON.parse() method: ... This section provides real-world scenarios and code examples demonstrating how to work with nested data. ... API Responses: Parsing JSON responses from APIs that contain nested objects and arrays.
🌐
Codefinity
codefinity.com › courses › v2 › d797f15f-39dd-4abc-8cfd-0d898dd2b885 › 372339e2-bcc5-490c-a5ee-f4d51f680045 › e304b41b-64c3-4141-9977-18b5c16467ff
Learn JSON Arrays and Nested Objects | Understanding JSON Data
This structure is commonly used ... related records together. Nested objects in JSON occur when an object contains another object or an array as one of its values....
🌐
UiPath Community
forum.uipath.com › help
JSON Object parsing with nested Array - Help - UiPath Community Forum
Hello all, I tried to parse json below and I was able to get these nested ID but I was able to deserialize json and create json object but now I’m not able to "enter in events array. Can anyone help? Big thansk in advance { “sportId”: 33, “last”: 210756101, “league”: [ { “id”: 204735, “name”: “ATP Challenger Seoul - R2”, “events”: [ { “id”: 982609151, “starts”: “2019-05-01T02:00:00Z”, “home”: “Yan Bai”, “away”: “Evgeny Donskoy”, “rotNum”: “9359”, “liveStatus”: 0, “status”: “I”, ...
Published   April 30, 2019
🌐
Retool
community.retool.com › 💬 queries and resources
Adding nested array as value in JSON body - 💬 Queries and Resources - Retool Forum
April 26, 2023 - Hi. I am trying to nest an array of key-value pairs within the JSON body. I can't see why nesting the array within the JSON body as a value isn't working. Similarly, when I tried the alternative of just using raw JSON, …