Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access nested JSON in json2html

I'm using json2html to create a report for a given JSON file. I was wondering what exactly the syntax is to access nested objects and their fields. For example,

var jsonData = {
    "field1": "value1",
    "field2": "value2",

    "nestedObject": {
        "nestedField1": "nestedValue1",
        "nestedField2": "nestedValue2"
    }
}

What's the syntax to access "nestedField1"? The transform that I'm using is,

var transform = [ 
                  {tag : "h1", html : "${field1}"},
                  {tag : "article", html : "${field2}"},
                  {tag : "article", html : "${nestedObject}" }
                ]

The last statement html : "${nestedObject}" returns [Object object] as expected. But, I can't seem to access its fields.


1 Answers

"${nestedObject.nestedField1}"

This should do the trick.

Just like how you'd access it in JS:

jsonData.nestedObject.nestedField1
like image 61
Cerbrus Avatar answered Apr 27 '26 21:04

Cerbrus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!