I am currently working with an Odata endpoint and am having an issue referencing JSON values with tags including @. The console shows “SyntaxError | Invalid or unexpected token”
pm.test(“Your test name”, function () {
var jsonData = pm.response.json();
pm.expect(jsonData.@odata.count).to.eql(73);
});
Can someone explain how I reference that value?-
@greg.mackey
Try this: https://stackoverflow.com/questions/6932745/parsing-json-w-at-sign-symbol-in-it-arobase
pm.test(“Your test name”, function () {
var jsonData = pm.response.json();
pm.expect(jsonData.[@odata.count]).to.eql(73);
});
Mick
1 Like
After developing an over complicated solution with regex I read the article you attached. It was the correct solution. Thank you. Slight update to the script you provided. There is no dot before the property (jsonData[@odata.count])
pm.test(“Your test name”, function () {
var jsonData = pm.response.json();
pm.expect(jsonData[@odata.count]).to.eql(73);
});
@greg.mackey
Glad you figured it out. I had to go back and look at some of my tests where I have “0” and “$” to deal with. Then I remembered when I was trying to figure out those there wasn’t a “.” used as well.
Mick