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:

Copyorders: {

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:

Copy"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:

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

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

Answer from Corkscreewe 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:

Copyorders: {

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:

Copy"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:

Copyobj.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:

Copy   {
    "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:

Copy$(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");

});

});

🌐
Lokalise
docs.lokalise.com › en › articles › 1400773-json-nested-json
JSON nested (.json) | Lokalise Help Center: Documentation and helpful resources
Force object type: The triple colon (:::) is used as a force object type for the resulting JSON. ... These keys will be exported back as an array if all the sequential keys are present. If the keys follow a sequential pattern with :: and one key corresponds to position 0, they will still be exported as an array, and the missing positions will be filled with empty strings. For example, if main::1 is deleted, and only main::0 and main::2 are present:
🌐
Adobe
opensource.adobe.com › Spry › samples › data_region › JSONDataSetSample.html
JSON Data Set Sample
Example 5 - The "path" constructor option and JSON Array with objects as elements. Example 6 - The "subPaths" constructor option with a single path. Example 7 - The "subPaths" constructor option with multiple paths. Example 8 - "path" constructor option example. Example 9 - Multiple matches for a single sub path. Example 10 - Multiple matches for multiple sub paths. Example 11 - The JSON Nested Data Set.
🌐
CodeSignal
codesignal.com › learn › courses › parsing-json-with-csharp › lessons › parsing-json-arrays-and-nested-structures
Parsing JSON Arrays and Nested Structures
Take a look at the nested employee lists in each department from data.json: Similarly, each department contains another array called employees.
🌐
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
... 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]); ...
Published   July 23, 2025
🌐
Latenode
community.latenode.com › other questions › javascript
How can I access a nested array within a JSON file?
October 29, 2024 - 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]. ...
🌐
Phrase
support.phrase.com › hc › en-us › articles › 6111330881692--JSON-Nested-Strings
.JSON - Nested (Strings) – Phrase
AI chatbots can be very effective at generating a list of keys from a .JSON file. { "boolean_key": "--- true\n", "empty_string_translation": "", "key_with_description": "Check it out! This key has a description! (At least in some formats)", "key_with_line-break": "This translations contains\na line-break.", "nested": { "deeply": { "key": "Wow, this key is nested even deeper."
Find elsewhere
🌐
JMP User Community
community.jmp.com › t5 › Discussions › How-do-you-import-JSONs-that-contain-double-nested-arrays › td-p › 533809
How do you import JSONs that contain double nested arrays? - JMP User Community
June 10, 2023 - ... Names Default To Here(1); aa = Load Text File(pickfile(), "JSON"); /* since only the "prediction" key of the main array produces varying row values, the following AA can be used to write those columns with nonvarying values, after all else ...
🌐
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 • ...
🌐
Medium
medium.com › @ferzia_firdousi › multi-level-nested-json-82d29dd9528
Deeply Nested JSON, json.normalize, pd.read_json | Medium
May 3, 2023 - Reading the JSON into a pandas object shows that _df[‘students’] is a multi-level nested key-value pair enclosed in a list, whereas _df[‘school_name’] and _df[‘class’] are single key-value pairs (multi-level key-value pair is only one format: list).
🌐
Workiva
support.workiva.com › hc › en-us › articles › 19581207597460-CLP-JSON-Array-of-Nested-Objects
CLP - JSON Array of Nested Objects – Support Center
Use the HTTP Connector to retrieve donut data from a web location. This dataset illustrates an example of a more complex JSON dataset with an array (multiple items) of nested objects (attributes).
🌐
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
I used hierarchy to create an array out of my jSON inputs which resolved the issue. ... To generate arrays in your data, you will use an Aggregate transformation with the collect() function. We have an example video of this here: https://www.youtube.com/watch?v=zneE18EHJSE
🌐
ArduinoJson
arduinojson.org › version 5 › faq › how to create complex nested objects?
How to create complex nested objects? | ArduinoJson 5
July 9, 2025 - To create a nested object, call createNestedObject(). To create a nested array, call createNestedArray(). ... DynamicJsonBuffer jsonBuffer; JsonObject& root = jsonBuffer.createObject(); JsonObject& weather = root.createNestedObject("weather"); weather["temperature"] = 12; weather["condition"] = "cloudy"; JsonArray& coords = root.createNestedArray("coords"); coords.add(48.7507371, 7); coords.add(2.2625587, 7); root.prettyPrintTo(Serial);
🌐
Stitch Docs
stitch-docs.netlify.app › docs › data-structure › nested-data-structures-row-count-impact
Nested JSON Data Structures & Row Count Impact | Stitch Documentation
When Stitch receives a nested array - or an array that’s inside a JSON record - like the one above, it will “denest” it from the parent structure and create a subtable. To give you a better understanding of how Stitch denests arrays, we’ll walk you through an example using a Shopify ...
🌐
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, …
🌐
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 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. Configuration Files:Reading configuration settings from JSON files.
🌐
W3Schools
w3schools.com › js › js_json_arrays.asp
JSON Arrays
JS Examples JS HTML DOM JS HTML Input JS HTML Objects JS HTML Events JS Browser JS Editor JS Exercises JS Quiz JS Website JS Syllabus JS Study Plan JS Interview Prep JS Bootcamp JS Certificate JS Reference ... Arrays in JSON are almost the same as arrays in JavaScript.