I try to retrieve a value from a JSON server response, but the JSonPath check returns a wrong value.
The server response looks like the following JSON content :
{
“name”:“The system 21450001-000001”,
“applications”:[{“uid”:“cdb6c07c2e544f4e83846185364efce0”,“name”:“perf-msci-app-6668fc842f5a46418c45caf3773da9f1”,“revision”:“V1.0”,}],
“gateway”:{“imei”:“21450001-000001”,“macAddress”:null,“serialNumber”:“21450001-000001”,“type”:null,“uid”:“c0ca8e6a6ffc4fc2860bb77898539e4b”,“state”:“INVENTORY”},
“uid”:“553e68f54455486b87d846e462118a47”,
“state”:“INVENTORY”,
“activityState”:“ACTIVATED”
}
I want to retrieve the field " /uid “, but the “.check(jsonPath(”/uid”)" returns the value of the first “uid” field found.
Indeed, in my case, it returns the value of the field “/applications/uid”, so it’s wrong.
@Sébastien I was able to fix it (didn’t push yet), but I have a problem with your sample.
The application element has a trailing comma that’s actually illegal, even if some browsers do support it (yet another way to encourage internet mess…).
Are you sure you were able to parse it with Gatling (even if the result was wrong) or did you actually edit it to make it shorter? Because Jackson (the underlying JSON engine) isn’t supposed to support this.
“applications”:[{“uid”:“cdb6c07c2e544f4e83846185364efce0”,“name”:“perf-msci-app-6668fc842f5a46418c45caf3773da9f1”,“revision”:“V1.0”, ← illegal comma here }],