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
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");

});

});

🌐
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
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:
Discussions

Creating Nested JSON Objects
I’m a bit stuck trying to create another “nest” or “hierarchy” in my json object. My current and ideal states are below: Current [{ “recordtype” : “noninventoryitem”, “id” : 22301, “values” : { “itemid” : “SKU1234”, “displayname” : “Very Unique SKU Series ... More on forum.knime.com
🌐 forum.knime.com
1
0
September 2, 2022
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
Accessing data in nested json
hey everyone, please excuse my beginners issues but I am having some really hard time accessing items in nested json. At the moment I am trying to simply get the title url (found in source) main_name (found in actors) aliases (also found in actors) from json that looks like this { "id": ... More on community.retool.com
🌐 community.retool.com
1
0
March 5, 2023
Build a double nested JSON object
In your wanted output, content is a list so just declare it as such then append whatever data you want to it. import json json_data = {} json_data["content"] = [] content = {} content["eventType"] = "view" content["othervar"] = "new" json_data["content"].append(content) print(json.dumps(json_data, indent=4)) # Output { "content": [{ "eventType": "view", "othervar": "new" }] } More on reddit.com
🌐 r/learnpython
3
1
January 23, 2024
🌐
Medium
medium.com › @ferzia_firdousi › multi-level-nested-json-82d29dd9528
Deeply Nested JSON, json.normalize, pd.read_json | Medium
May 3, 2023 - Even though this JSON is deeply nested, it only has single-level key-value pairs or multi-level key-value pairs in a list. The following code will clean it easily. # loading the file into JSON with open(r'Sample_4.json') as f: d = json.load(f) # dumping the load into a pandas object and save it df = pd.DataFrame(d) # normalize and dump the load into a ANOTHER temporary pandas dataframe temp = pd.json_normalize(d, record_path =['students']) # combining the final dataframes Final = pd.concat([df.drop(['students'], axis = 1), temp], axis = 1) Final
🌐
Adobe
opensource.adobe.com › Spry › samples › data_region › JSONDataSetSample.html
JSON Data Set Sample
Example 11 - The JSON Nested Data Set. Example 12 - Sorting with the JSON Nested Data Set
🌐
Qlik Community
community.qlik.com › t5 › Member-Articles › Parsing-Nested-JSON-Objects › ta-p › 2535112
Parsing: Nested JSON Objects - Qlik Community - 2535112
November 4, 2025 - Unlike the previous post Parsing: Flat JSON - Field Value Pairs this structure has more than just the fields and values it has entity structure. The · name field isn't a standalone name, it's part of the ... sheriff's office isn't just a field ...
Find elsewhere
🌐
Reddit
reddit.com › r/swift › is there a neat way to work with deeply-nested json?
r/swift on Reddit: Is there a neat way to work with deeply-nested JSON?
April 3, 2023 -

My app uses deeply-nested JSON fetched from an API. My problem is that the structure of the JSON really does not fit what I need as I have to mix & match data from various levels of the JSON.

The approach I've taken so far is to decode the JSON into Decodable structs and then use helper functions to turn these Decodable structs into the structs that I actually need. I'm not a fan of this approach because it looks messy but I understand that for Decodable to do its job, the nesting structure of the Decodable structs has to match that of the JSON. Therefore, I can't just decode straight into the structs that I need and I have to go via these Decodable 'intermediaries'.

Am I missing something? Is there a better approach? I really hope so because this feels terribly wasteful, but my research so far hasn't yielded great results.

Edit: just to be clear - it's not the decoding itself that's the problem, I know how to use Decodable (especially with the help of quicktype!). I'm just trying to minimise the amount of Decodable structs that I need to use to decode multi-level JSON. From the comments thus far it just seems like that's not really an option.

🌐
CodeSignal
codesignal.com › learn › courses › parsing-json-with-csharp › lessons › parsing-json-arrays-and-nested-structures
Parsing JSON Arrays and Nested Structures
This JSON array consists of two objects representing individuals, each with a name and age attribute. Understanding this structure is key as we parse more complex nested arrays in subsequent sections. ... Let's begin with parsing a straightforward JSON array using a loop. Consider the JSON array of departments provided in data.json: Here's how you can parse this JSON array using a loop in C#: ... In this example, we extract the departments JSON array from the parsed data and iterate over each department using a foreach loop over a JArray.
🌐
Retool
community.retool.com › 💬 queries and resources
Accessing data in nested json - 💬 Queries and Resources - Retool Forum
March 5, 2023 - hey everyone, please excuse my beginners issues but I am having some really hard time accessing items in nested json. At the moment I am trying to simply get the title url (found in source) main_name (found in actors) aliases (also found in actors) from json that looks like this { "id": "123456789", "title": "brad pitt on the rise", "authors": "brian j. robb", "language": "EN", "sources": [{ "id": "123456789", "name": "imdb", "url": "https://www.imdb.com/name/nm00000...
🌐
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."
🌐
Reddit
reddit.com › r/learnpython › build a double nested json object
r/learnpython on Reddit: Build a double nested JSON object
January 23, 2024 -

This is what I want to generate to match a required file format (notice the extra level of brackets):

{
    "content": [{
        "eventType": "view",
        "othervar": "new"
    }]
}

sample code:

import json

jsondata = {}
content={}
content['eventType'] = 'view'
content['othervar'] = "new"

jsondata['content'] = content
print(json.dumps(jsondata, indent=4))

Current output:

{
    "content": {
        "eventType": "view",
        "othervar": "new"
    }
}  

EDIT: Thanks so much. I come from a long R background and am still learning the Python details.

🌐
JSON Schema
json-schema.org › learn › miscellaneous-examples
JSON Schema - Miscellaneous Examples
The provided data conforms to the schema by including values for the required properties and ensuring the age is an integer greater than or equal to zero. The address object contains all the necessary properties, and the hobbies property is an array of strings. In this example, the dependentRequired keyword is used to specify that the property bar is required when the property foo is present.
🌐
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, …
🌐
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 - Each friend is an object, and this object again contains a nested array with the friend’s hobbies. ... The JSON data format does not support a date type. There are different ways to have a date in a JSON document.
🌐
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 - This allows you to create hierarchical structures, grouping related attributes together.2 ... Representing “has-a” relationships: For example, a user object “has an” address object.
🌐
Bubble
forum.bubble.io › need help › apis
Nested JSON Object - APIs - Bubble Forum
September 10, 2022 - How would you handle a nested JSON object within a JSON object in an API workflow? (Saving response data to database) example “result”: [ { “id” “type” “files”: […] <<<<< nested in results } ] //inside of ne…
🌐
n8n
community.n8n.io › questions
Nested json read as [object Object] - Questions - n8n Community
March 7, 2024 - Describe the problem/error/question I build a workflow which execute an http api call and return as a response an array of objects, than i want to send this array of objects to a discord message but the message is published with [object Object]. This is the mark down i created ## Alert Details - **Campaign items**: {{$json}} - **Time of Occurrence**: {{ new Date() }} this is the json response i am get [ { "items": [ { ...data }, { ...data } ],...
🌐
JSON API
discuss.jsonapi.org › t › how-to-represent-deeply-nested-objects-resources › 1782
How to represent deeply nested objects/resources? - JSON API
December 9, 2019 - Hi, I’d like to know your thoughts on how to represent deeply nested objects. From what I understand, all related objects should be returned from the relationships field. What is better when we have reasonably deep rela…