0

My request body looks like this enter image description here

"pulic_token" variable is ready defined.

My pre-request test looks like this:

pm.test("Public token is correct", () => {
    const req = JSON.parse(request.data);
    pm.expect(req.public_token).to.be.a("string");
});

The error:

JSONError: Unexpected token 'p' at 4:21 "public_token": {{public_token}} ^
ericn
  • 12,476
  • 16
  • 84
  • 127

2 Answers2

0

Every “string” must be quoted with double quote

Oleg Andreyev
  • 647
  • 5
  • 20
  • Why does postman assume that my "public_token" is a string? Type confusion is a possible mistake and I'm trying to test that – ericn Jan 03 '21 at 16:44
  • It has nothing to do with postman, it’s a JSON specification https://www.json.org/json-en.html only numbers, object and arrays can be without quotes – Oleg Andreyev Jan 03 '21 at 17:00
0

The error is from

JSON.parse(request.data)

The error says :

JSONError: Unexpected token 'p' at 4:21 "public_token": {{public_token}} ^

THis indicate that public_token variable was not resolved , if it was resolved the error would be something like (assuming value of variable is pet)

JSONError: Unexpected token 'p' at 4:21 "public_token": pet ^ 

So check whether correct environment or variable is defined

Output:

  1. when environment not selected

  2. when environment was selected

enter image description here

PDHide
  • 18,113
  • 2
  • 31
  • 46