Let say I have json data like
data = {"id":1, "name":"abc", "address": {"streetName":"cde", "streetId":2 } } Now I am getting fields to be accessed from this json data like : fields = ["id", "name", "address.streetName"]
How could I access third field (address.streetName) from given json data in most efficient way? data.fields[2] doesn't work
One possibility is I construct data[address][streetName] string using a for loop and do eval of that but is there any efficient way of doing this?
eval, which is not exactly ideal! To use eval:var your_variable = eval("data." + x);