0

Totally noob question from me. Different from other JSON nested questions, I want to access the value of the middle level. Consider that I have a JSON like:

  "nodes":[
    {"Level1":[
          {"Level2A":[
              {"Level3A":"Value",
               "Level3B":"Value"
              },
              {"Level3A":"Value",
               "Level3B":"Value"
              }]
          },
          {"Level2B":[
              {"Level3A":"Value",
               "Level3B":"Value"
              },
              {"Level3A":"Value",
               "Level3B":"Value"
              }]
           }]    
        }]

I want to get the value of Level2 out(to use as label). I can get lv3 value by calling for example,:

node.datum().Level1[0].Level2[0].Level3A

but if I tried

nodae.datum().Level1[].Level2

I get an object instead. The ideal output would be the array with [Level2A, Level2B,...]

Loredra L
  • 1,485
  • 2
  • 16
  • 32

1 Answers1

0

Are you sure your json is in valid mode or you just post half of it? That what I did-

{"nodes":[{"Level1":[{"Level2A":[{"Level3A":"Value","Level3B":"Value"},{"Level3A":"Value",   "Level3B":"Value"}],"Level2B":[{"Level3A":"Value","Level3B":"Value"}]}]}]}
The scion
  • 1,001
  • 9
  • 19
  • Yeah, there were mistakes. I edited my questions, hope that nothing is wrong – Loredra L Apr 12 '16 at 13:25
  • ok, but you got an object because it is in mode of json. you can use some function for mapping the object into array like this-Array.map http://stackoverflow.com/questions/20881213/converting-json-object-into-javascript-array – The scion Apr 12 '16 at 13:43