M
M
mafe_ru2017-09-01 07:49:29
JavaScript
mafe_ru, 2017-09-01 07:49:29

How to "reach" dot notation to a nested object in JSON?

Help with a rather stupid question, but I don’t understand how, I’ve covered the floor of the Internet.
I'm using Vue.js getting from JSON base:

"programs" : {
    "Abs" : [ null, {
      "bR" : 10.5,
      "dR" : {
        "oR" : 0,
        "p" : 0,
        "pro" : 0
      },
      "fP" : 15,
      "l" : "O7",
      "name" : "Один из многих",
      "tD" : {
        "bR" : 0,
        "fP" : 0
      },
      "uR" : {
        "i" : 0,
        "s" : 0
      }
    }]
  Two: {
  "id" : 555
}
}

At the first levels of nesting, I understand how to "reach"
{{programs[1].id}} // Выводит 555
And what to do with deeper nesting? Can someone explain popularly and if possible, with an example?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Ptolemy_master, 2017-09-01
@mafe_ru

It's the same way to get:

programs["Abs"][2]["name"] //Один из многих
programs["Abs"][1]["dr"]["p"] //0

But do you really need it?

A
akass, 2017-09-01
@akass

You can try JsonPath

K
kulaeff, 2017-09-01
@kulaeff

First, your JSON is invalid. Second, the path programs["Abs"][2] does not exist because programs["Abs"] contains an array of only 2 elements, indexed 0 and 1. Here are examples of how to get some then properties from your json:

programs.Abs[1].bR
programs.Abs[1].dR.oR
programs.Abs[1].name
programs.Two.id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question