๐ŸŒ
W3Schools
w3schools.io โ€บ json-sample-examples
Learn JSON sample examples - w3schools
December 31, 2023 - JSON Example contains an array ... { "roles": ["admin", "employee", "user", "visitor"] } Nested JSON Object The object contains a key and value....
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ tryit.asp
Access Nested JavaScript Objects
The W3Schools online code editor allows you to edit code and view the result in your browser
๐ŸŒ
W3Schools
w3schools.io โ€บ file โ€บ json-cheatsheet
JSON cheatsheet complete tutorial with examples - w3schools
December 31, 2023 - ... 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.
๐ŸŒ
W3Resource
w3resource.com โ€บ javascript-exercises โ€บ fundamental โ€บ javascript-fundamental-exercise-6.php
JavaScript fundamental (ES6 Syntax): Target a given value in a nested JSON object - w3resource
July 3, 2025 - // Source: https://bit.ly/2neWfJ2 // Define a function called `dig` that searches for a target key in a nested object. const dig = (obj, target) => target in obj // Check if the target key exists in the object.
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_json_objects.asp
W3Schools.com
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 Certificate ... A JSON object is enclosed in curly braces { }.
๐ŸŒ
W3Schools
w3schools.in โ€บ json โ€บ objects
JSON Objects - W3Schools
The dot (.) or period operator needs to be used to access the nested object elements. The more you access the nested elements, the more you have to add dots. Let suppose you want to delete the subject1 from that previous JSON example so that you can use the delete keyword followed by this:
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ tryit.asp
Nested JavaScript Objects and Arrays.
The W3Schools online code editor allows you to edit code and view the result in your browser
๐ŸŒ
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.
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
W3Resource
w3resource.com โ€บ JSON โ€บ structures.php
JSON Structures | JSON tutorial | w3resource
If the JSON data describes an array, and each element of that array is an object. [ { "name": "Bidhan Chatterjee", "email": "[email protected]" }, { "name": "Rameshwar Ghosh", "email": "[email protected]" } ] Remember that even arrays can also ...
๐ŸŒ
W3Resource
w3resource.com โ€บ JSON โ€บ introduction.php
JSON Tutorial | w3resource
November 7, 2025 - Then '"Price"' label contains an array, which is turn contains two separate objects. Another example of nesting. Also, notice that numbers are not enclosed by quotations. The name behind popularizing the JSON is Douglas Crockford.
๐ŸŒ
Jsontech
jsontech.net โ€บ home โ€บ learn โ€บ nested json example
Nested JSON Example & Deep Structures | JSONTech.net
March 20, 2025 - Duplicating data across levels. In the example above, currency appears in payment. Don't repeat it inside breakdown too. Forgetting to handle missing keys. Always use optional chaining or equivalent when traversing nested JSON from external sources.
๐ŸŒ
W3Schools
w3schools.io โ€บ file โ€บ yaml-array-objects
YAML equivalent of an array of objects in JSON - w3schools
December 31, 2023 - data property contains a nested array of objects which can be YAML as follows
๐ŸŒ
Devtoolsbuilder
devtoolsbuilder.com โ€บ home โ€บ learn โ€บ json example library โ€บ nested & complex json
Nested & Complex JSON โ€“ JSON Example Library | DevToolsBuilder
A nested event payload with actor, context, and event-specific properties. Use this for event tracking, ingestion pipelines, and product analytics docs.Show explanations ... Important keys are documented separately below so the copied JSON stays valid and production-safe. ... Browse curated example families by use case.
๐ŸŒ
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
Top answer
1 of 4
4

Your input string is wrong

<p id="demo"></p>

 <script>
 var text='{ "rajaongkir":{ '
+ '  "query":{'
+'     "origin":"501",'
+'     "destination":"114",'
+'     "weight":1700,'
+'     "courier":"jne"'
+'  },'
+'  "status":{'
+'     "code":200,'
+'     "description":"OK"'
+'  },'
+'  "origin_details":{'
+'     "city_id":"501",'
+'     "province_id":"5",'
+'     "province":"DI Yogyakarta",'
+'     "type":"Kota",'
+'     "city_name":"Yogyakarta",'
+'     "postal_code":"55000"'
+'  },'
+'  "destination_details":{'
+'     "city_id":"114",'
+'     "province_id":"1",'
+'     "province":"Bali",'
+'     "type":"Kota",'
+'     "city_name":"Denpasar",'
+'     "postal_code":"80000"'
+'  },'
+'  "results":['
+'     {'
+'        "code":"jne",'
+'        "name":"Jalur Nugraha Ekakurir (JNE)",'
+'        "costs":['
+'           {'
+'              "service":"OKE",'
+'              "description":"Ongkos Kirim Ekonomis",'
+'              "cost":['
+'                 {'
+'                    "value":38000,'  //<<<<<<  GET THIS VALUE
+'                    "etd":"4-5",'
+'                    "note":""'
+'                 }'
+'              ]'
+'           },'
+'           {'
+'              "service":"REG",'
+'              "description":"Layanan Reguler",'
+'              "cost":['
+'                 {'
+'                    "value":44000,'
+'                    "etd":"2-3",'
+'                    "note":""'
+'                 }'
+'              ]'
+'           },'
+'           {'
+'              "service":"SPS",'
+'              "description":"Super Speed",'
+'              "cost":['
+'                 {'
+'                    "value":349000,'
+'                    "etd":"",'
+'                    "note":""'
+'                 }'
+'              ]'
+'           },'
+'           {'
+'              "service":"YES",'
+'              "description":"Yakin Esok Sampai",'
+'              "cost":['
+'                 {'
+'                    "value":98000,'
+'                    "etd":"1-1",'
+'                    "note":""'
+'                 }'
+'              ]'
+'           }'
+'        ]'
+'     }'
+'  ]}}';  
   obj=JSON.parse(text);
   document.getElementById("demo").innerHTML=
   obj.rajaongkir.results[0].costs[0].cost[0].value;
   </script>
2 of 4
2

Your JSON is not a valid string literal. There are no line breaks allowed, unless you end every line with a \.

If you add these \, everything is fine:

https://jsfiddle.net/ec3n6f20/

๐ŸŒ
Medium
medium.com โ€บ @ferzia_firdousi โ€บ multi-level-nested-json-82d29dd9528
Deeply Nested JSON, json.normalize, pd.read_json | Medium
May 3, 2023 - We load it into JSON and introduce the .json_normalize() function for straightening the nested key-value pair.
๐ŸŒ
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
Nested objects in JSON occur when an object contains another object or an array as one of its values. In the product list above, each item in the array is itself an object with its own properties.
๐ŸŒ
Plain English
python.plainenglish.io โ€บ data-extraction-parse-a-3-nested-json-object-23cb978b66ad
Data Extraction: Parse a 3-Nested JSON Object and Convert it to a pandas dataframe | by Tejeswini | Python in Plain English
June 10, 2021 - For example, { โ€˜dataโ€™ : [ {โ€˜screen_IDโ€™ : โ€˜63โ€™, in this instance โ€˜dataโ€™ and โ€˜screen_IDโ€™ are the keys, and โ€˜63โ€™ is the value. Keys must be strings, and values must be a valid JSON data type (string, number, object, array, boolean or null). Join Medium for free to get updates from this writer. ... So, what is a Nested-JSON?
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");

});

});