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

Answer from Corkscreewe on Stack Overflow
🌐
Adobe
opensource.adobe.com › Spry › samples › data_region › JSONDataSetSample.html
JSON Data Set Sample
Doing that with the data set used in Example 10 would require some JavaScript logic embedded in spry attribute conditionals to control when things showed up. A simpler approach would be to use NestedJSONDataSets. In this example we use the same JSON data used in Example 10, but we will use 2 nested JSON data sets to track the "batter" and "topping" data.
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

Working with nested JSON | OutSystems
Im working on an app where i need to use values from a nested JSON object. Im currently trying to create a list of data that uses the following json object seen in this image: · Problem is that im trying to create a list from these values that have "SystemID", "ID" and "Name" More on outsystems.com
🌐 outsystems.com
Nested JSON objects - do I have to use arrays for everything?
You have too many redundant nested arrays inside your jSON data, but it is possible to retrieve the information. More on stackoverflow.com
🌐 stackoverflow.com
Is there a neat way to work with deeply-nested JSON?
What you’re describing are “Data Transfer Objects”, or DTOs. It’s very common to have DTOs that match the data from your API, that are then used to manipulate the data into the objects you actually want to use on the client, so working with the messy or bad (or just full of unneeded) API data doesn’t infect your own client code. When you don’t control the data coming from the API, it’s an unfortunate necessity. I don’t have any experience with it, but apparently GraphQL is supposed to solve this, but not every API is going to offer it. You could manipulate the data in your decodable init, but then that gets to be pretty messy if you’re needing to do a lot of manipulation, and working with a DTO might end up being better anyways. More on reddit.com
🌐 r/swift
23
23
April 3, 2023
How do i pass complex and nested large json data as input to open ai model
Do you need to answer questions across all of that data at once? Or does each file represent a different entity you might ask about? More on reddit.com
🌐 r/OpenAI
40
24
August 21, 2023
🌐
QA With Experts
qawithexperts.com › article › javascript › nested-and-complex-json-examples › 446
Nested and Complex JSON examples - QA With Experts
June 26, 2024 - { "data": [ { "MainId": 1111, "firstName": "Sherlock", "lastName": "Homes", "categories": [ { "CategoryID": 1, "CategoryName": "Example" } ] }, { "MainId": 122, "firstName": "James", "lastName": "Watson", "categories": [ { "CategoryID": 2, "CategoryName": "Example2" } ] } ], "messages": [], // blank json "success": true // boolean value } In the above JSON, we have nested JSON inside "data" object, then we 2 values and inside that we have Categories Array.
🌐
GitHub
gist.github.com › 8574169
Sample nested json data for boilerplate coffee data · GitHub
Sample nested json data for boilerplate coffee data - sample_nested.json
🌐
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
Structure: Nested JSON files consist of key-value pairs, where values can be strings, numbers, arrays, or objects. This allows for complex, hierarchical data structures.
🌐
Medium
medium.com › @ferzia_firdousi › multi-level-nested-json-82d29dd9528
Deeply Nested JSON, json.normalize, pd.read_json | Medium
May 3, 2023 - _df = pd.read_json(r'Sample_3.json', typ='series') _df ... This pandas object shows two multi-level key-value pairs — a list and a dictionary. The combination of strings, dictionaries, and lists makes data normalization in one step, complicated.
🌐
Phrase
support.phrase.com › hc › en-us › articles › 6111330881692--JSON-Nested-Strings
.JSON - Nested (Strings) – Phrase
}, "key": "This key is nested inside a namespace." }, "null_translation": null, "pluralized_key": { "one": "Only one pluralization found.", "other": "Wow, you have %s pluralizations!", "zero": "You have no pluralization." }, "sample_collection": [ "first item", "second item", "third item" ], "simple_key": "Just a simple key with a simple message.", "unverified_key": "This translation is not yet verified and waits for it.
Find elsewhere
🌐
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 - In the following example you see a JSON object containing a list with friends. Each friend is an object, and this object again contains a nested array with the friend’s hobbies.
🌐
Microsoft Learn
learn.microsoft.com › en-us › sql › relational-databases › json › format-nested-json-output-with-path-mode-sql-server
Format Nested JSON Output with PATH Mode - SQL Server | Microsoft Learn
January 28, 2026 - The FOR JSON PATH clause uses the column alias or column name to determine the key name in the JSON output. If an alias contains dots, the PATH option creates nested objects. SELECT TOP 5 BusinessEntityID AS Id, FirstName, LastName, Title AS 'Info.Title', MiddleName AS 'Info.MiddleName' FROM Person.Person FOR JSON PATH;
🌐
OutSystems
outsystems.com › forums › discussion › 78920 › working-with-nested-json
Working with nested JSON | OutSystems
Im working on an app where i need to use values from a nested JSON object. Im currently trying to create a list of data that uses the following json object seen in this image: · Problem is that im trying to create a list from these values that have "SystemID", "ID" and "Name"
🌐
Stitch Docs
stitch-docs.netlify.app › docs › data-structure › nested-data-structures-row-count-impact
Nested JSON Data Structures & Row Count Impact | Stitch Documentation
Stitch is designed to deconstruct these nested structures into separate tables to easily query the data. ... When Stitch pulls data from an integration, it’s pulling a series of JSON records.
🌐
Datatables
editor.datatables.net › examples › advanced › deepObjects.html
DataTables example - Complex (nested) JSON data source
To clarify the difference between fields.data and fields.name, the former is used to read the value from the DataTables row's data, while the latter is the name of the field that is submitted to the server. Typically they will be the same, with the data property taking the value of the name automatically unless otherwise specified.
🌐
Teradata
docs.teradata.com › r › Enterprise_IntelliFlex_VMware › JSON-Data-Type › JSON-Shredding › TD_JSONSHRED › TD_JSONSHRED-Examples › Example-TD_JSONSHRED-Nested-Arrays
Example: TD_JSONSHRED Nested Arrays
Loading application · Promo placeholder · Tracking Consent Teradata.com · Developers · Getting Started · VantageCloud Lake Documentation AI Unlimited All Documentation · Downloads · Community · Teradata Community Technical Medium Blogs Github Stack Overflow · Try for free
🌐
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
🌐
AWS
docs.aws.amazon.com › amazon redshift › database developer guide › amazon redshift spectrum › tutorial: querying nested data with amazon redshift spectrum › serializing complex nested json
Serializing complex nested JSON - Amazon Redshift
This topic demonstrates how to serialize nested data in JSON format. Nested data is data that contains nested fields. Nested fields are fields that are joined together as a single entity, such as arrays, structs, or objects.
🌐
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 - 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).
🌐
Hackers and Slackers
hackersandslackers.com › extract-data-from-complex-json-python
Extract Nested Data From Complex JSON
December 22, 2022 - Let's say we only want the human-readable data from this JSON, which is labeled "text" for both distance and duration. We've created a function below dubbed json_extract() to help resolve this issue. The function is intended to be flexible and agnostic, therefore can be imported as a module into any project you might need. """Extract nested values from a JSON tree.""" def json_extract(obj, key): """Recursively fetch values from nested JSON.""" arr = [] def extract(obj, arr, key): """Recursively search for values of key in JSON tree.""" if isinstance(obj, dict): for k, v in obj.items(): if isinstance(v, (dict, list)): extract(v, arr, key) elif k == key: arr.append(v) elif isinstance(obj, list): for item in obj: extract(item, arr, key) return arr values = extract(obj, arr, key) return values
🌐
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 - While JSON allows deep nesting, it’s not always the best approach. The choice between a flatter structure (more top-level keys, less nesting) and a more nested structure involves trade-offs: ... Nested: If you often need all related data together (e.g., a user and their primary address), nesting can be efficient as it might be retrieved in a single operation, especially with document databases.
🌐
Medium
medium.com › @rahulgosavi.94 › handling-simple-json-nested-json-data-in-snowflake-9dbd7375c940
Handling Simple JSON/Nested JSON Data in Snowflake | by Rahul Gosavi | Medium
May 10, 2024 - We use the FLATTEN function to flatten the nested arrays (departments and employees) and create a table-like structure. We extract information such as company name, department details, and employee information using the json_data column and accessing nested fields with the : operator.