0

Json Looks like :

{"discovery": {
          "[AppCtrl Global]": {
            "ScriptFileTypes": ".cmd,.bat,.vbs,.wsf,.pl,.py,.ps1,.tcl,.rb",
            "name": "test"
          }
}
}

Now I want retrieve Name value, by using postman

console.log(discovery);  // This is giving me complete object

But when trying

console.log(discovery."[AppCtrl Global]".name)  // Error
console.log(discovery."AppCtrl Global".name)  // Error
Dev
  • 2,739
  • 2
  • 21
  • 34

2 Answers2

0

Option 1

You have an error on your sintax. If you want to access to a key from object, you have to do like this

// use
const name = discovery["[AppCtrl Global]"].name;
// instead of 
const name = discovery."[AppCtrl Global]".name;

Option 2

If discovery only has one key, you can do that with Object.values. Ej

const name = Object.values(discovery)[0].name;

We do [0] if name if in the first key of discovery.

Hope, help you

PD. I dont speak english very well

Denes
  • 106
  • 1
  • 1
  • 5
0

You can access the name property by using Object.values() method

let test = {"discovery": { "[AppCtrl Global]": { "ScriptFileTypes": ".cmd,.bat,.vbs,.wsf,.pl,.py,.ps1,.tcl,.rb", "name": "test" } } };

const values = Object.values(test.discovery);
console.log(values[0].name);
Hamad Javed
  • 106
  • 6