Hi PM Community,
I am able to access the below mentioned JSON Object’s values using the dot notation but the problem is that the order of the response keeps changing. I am new to implementing lodash methods but I had success with returning them to console.
{
“resourceType”: “picture”,
“id”: “VIVEK”,
“meta”: {
“versionId”: “v0.3”,
“lastUpdated”: “timestamp here”,
“source”: “MyPC”,
“profile”: [
“http://profilereferenceURLhere.com”
]
},
“text”: “ignored”,
“identifier”: [
{
“type”: {
“encoding”: [
{
“system”: “http://urlme.com”,
“code”: “ABC”,
“display”: “Display 00”
}
]
},
“value”: “123”
},
{
“type”: {
“encoding”: [
{
“system”: “http://yahoo.com”,
“code”: “ABCD”,
“display”: “Display 01”
}
]
},
“value”: “1777755555”
},
{
“type”: {
“encoding”: [
{
“system”: “https://google.com”,
“code”: “ABCDE”,
“display”: “Display 02”
}
]
},
“value”: “123OLD”
},
{
“type”: {
“encoding”: [
{
“system”: “http://myURL.com”,
“code”: “PER”,
“display”: “Display 03”
}
]
},
“value”: “1111111111”
},
{
“type”: {
“encoding”: [
{
“system”: “http://dummyurl.com”,
“code”: “HUT”,
“display”: “Display 04”
}
]
},
“value”: “999777888”
}
]
}
Below is my code to return the code for the first element in the array:
pm.test(“Test Lodash”, () => {
_.each(jd1.json.identifier[0].type.encoding, (item) => {
console.log(item.code);
})
});
I wish to validate if the code - “ABC” and the value is “123”. I am having trouble with asserting these values. I tried the below code as well:
pm.test(“Test Lodash 2”, () => {
_.each(jd1.json.identifier, (item) => {
console.log(item);
})
});
This returns a JSON response but I have issues in accessing the values I need to validate them.