0

// JSON that I have
const data = `{
    "accounts": {
        "aaa@gmail.com": {
            "zipcode": "",
            "inCharge": ""
       },
        "bbb@gmail.com": {
            "zipcode": "",
            "inCharge": ""
       },
        "ccc@gmail.com": {
            "zipcode": "",
            "inCharge": ""
       }
    }
}`

const records = JSON.parse(data);
const columns = Object.keys(records.accounts.aaa@gmail.com);

I have tried the following, none of which did work:

records.accounts.aaa@gmail.com records.accounts.["aaa@gmail.com"]
records.accounts.eval("aaa@gmail.com")
Mushroomator
  • 6,516
  • 1
  • 10
  • 27
ei c4
  • 1
  • Please be more precise with what you are trying to achieve? It's not clear at all. Verify the validity of the email address?(-> use RegEx) Loop through all the emails? (-> use `Object.keys(data.accounts)` or `Object.entries(data.accounts)`) Or just access the value using the email address? (-> use `records.accounts["aaa@gmail.com"]`) – Mushroomator Apr 26 '22 at 13:27
  • Object.keys(records.accounts.["aaa@gmail.com"]) --> get "zipcode","inCharge" --> read this column make sql table i want but can't access object.object.object --> records.accounts.["aaa@gmail.com"] --> aaa@gmail.com can't get object – ei c4 Apr 26 '22 at 14:00

1 Answers1

-1

You can access it using array accessor

const data = {
    "accounts": {
        "aaa@gmail.com": {
            "zipcode": "",
            "inCharge": ""
       },
        "bbb@gmail.com": {
            "zipcode": "",
            "inCharge": ""
       },
        "ccc@gmail.com": {
            "zipcode": "",
            "inCharge": ""
       }
    }
}

console.log(data.accounts["aaa@gmail.com"])
R4ncid
  • 6,944
  • 1
  • 4
  • 18