My goal is to be able to keep track of my position/depth in a JSON tree by adding elements to an Array and then access nested nodes in the JSON utilizing this Array. By now say the Array foo
it has one element:
foo = ["customers"]
so that element would act as a reference for a JSON children, say:
jsonTree["customers"]
where jsonTree is something like:
{
"customers":{
"name": "J. Goldsmith",
"orders": [{
"order": "1",
"order": "2"
}]
}
}
Then foo
eventually varies its size and become
foo = ["customers","orders"]
So the JSON reference would become
jsonTree["customers"]["orders"]
Now say that customers.orders
can become customers.orders.order.date.etc.etc
... Is there any way to build the jsonTree
reference programmatically with N dimensions based on the N elements of foo
Array?
Some examples:
I have ["John","Williams"]
-> i want to build composer["John"]["Williams"]
["Erich","Wolfgang","Korngold"] -> i want to build composer["Erich"]["Wolfgang"]["Korngold"]