2

I am trying to parse "Id" from below json to store it in a variable

{
    "cf35864e-944d-11e9-8aff-22000ab8d684": {
        "Id": "1a45b704-944e-11e9-8aff-22000ab8d684",
        "Name": "Test plan",
        "Type": "Limited",
        "Credits": 10119.70,
        "AvailableCredits": 500.100
    }
}

I've tried

bodydata =JSON.parse(responseBody)
planid=bodydata.cf35864e-944d-11e9-8aff-22000ab8d684.Id
console.log(planid)

But postman throws errors, is there any way so that only ID can be fetched.

Harsha Venkataramu
  • 2,887
  • 1
  • 34
  • 58

2 Answers2

0

This should work: planid=bodydata["cf35864e-944d-11e9-8aff-22000ab8d684"]['Id']

Christian Baumann
  • 3,188
  • 3
  • 20
  • 37
-1

As per your mentioned JSON data, the below may work.

let resp = pm.response.json();

console.log(resp.cf35864e-944d-11e9-8aff-22000ab8d684.Id);

Above will work only if "cf35864e-944d-11e9-8aff-22000ab8d684" value is static and only one object is returned.

Komal Padaria
  • 19
  • 1
  • 5