Search code examples
postmanpostman-testcase

Postman: How to retrieve value when key is array


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

Solution

  • 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);