0
{
    "1": {
        "emails": [
            {
                "address": "[email protected]",
                "verified": true
            }
        ],
        "_id": "dgBWJ4qBNsxa9a4MketL",
        "createdAt": "2019-07-23T15:33:34.270Z",
        "username": "[email protected]",
        "profile": {
            "active": true
        }
    }
}

i want to access "[email protected]" from the "address"

This is what i have tried

{ key: "emails[0].address", label: "Email" }
1

3 Answers 3

1

If you want to access the value, you shouldn't use quotation marks.

emails[0].address

Just like that to access the value, no quotation marks.

But it depends from what programming language did you use.

Sign up to request clarification or add additional context in comments.

1 Comment

this was for react js. sorry for not mentioning that.
1

You missed getting the child with the key "1" of the outer JSON object.

Let's say after you parse this JSON string (jsonString) into a JS Object you get the following:

let jsonObject = parse(jsonString);
console.log(jsonObject['1']['emails'][0]['address']); // <== This is what you are looking for

1 Comment

this was for react js. sorry for not mentioning that.
1

var objData = {
  "1": {
    "emails": [{
      "address": "[email protected]",
      "verified": true
    }],
    "_id": "dgBWJ4qBNsxa9a4MketL",
    "createdAt": "2019-07-23T15:33:34.270Z",
    "username": "[email protected]",
    "profile": {
      "active": true
    }
  }
}
var newOnbject = {};
var keys = Object.keys(objData);
for (var i = 0; i < keys.length; i++) {
  var key = keys[i];
  newOnbject.key = objData[key].emails[0].address;
  newOnbject.label = "Email"
}
console.log(newOnbject)

Note: Thou avoided receiving each child key of the external JSON objects.

1 Comment

this was for react js. sorry for not mentioning that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.