0

// JSON that I have
const data = `{
    "accounts": {
        "[email protected]": {
            "zipcode": "",
            "inCharge": ""
       },
        "[email protected]": {
            "zipcode": "",
            "inCharge": ""
       },
        "[email protected]": {
            "zipcode": "",
            "inCharge": ""
       }
    }
}`

const records = JSON.parse(data);
const columns = Object.keys([email protected]);

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

[email protected] records.accounts.["[email protected]"]
records.accounts.eval("[email protected]")
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["[email protected]"]`) – Mushroomator Apr 26 '22 at 13:27
  • Object.keys(records.accounts.["[email protected]"]) --> get "zipcode","inCharge" --> read this column make sql table i want but can't access object.object.object --> records.accounts.["[email protected]"] --> [email protected] 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": {
        "[email protected]": {
            "zipcode": "",
            "inCharge": ""
       },
        "[email protected]": {
            "zipcode": "",
            "inCharge": ""
       },
        "[email protected]": {
            "zipcode": "",
            "inCharge": ""
       }
    }
}

console.log(data.accounts["[email protected]"])
R4ncid
  • 6,944
  • 1
  • 4
  • 18