"JSONParser" is not defined, error while parsing JSON

Sushma Uday C
Tera Contributor

Hi all,

I am trying to parse JSON object and retrieve a token form JSON. And I am getting error as "JSONParser" is not defined.

Please find the below JSON and code for your reference.

JSON we are receiving

find_real_file.png

find_real_file.png

I want to retrieve the idToken form JSON. but I am getting an error as "JSONParser" is not defined.

 

Thanks in Advance,

Sushma Uday C

1 ACCEPTED SOLUTION

If responseBody1 is a JSON string you need to parse it initially like:

var responseObj1 = responseBody1;

var responseObj1Parsed = JSON.parse(responseObj1);

 

Then you can assess the token using:

var token = responseObj1Parsed.token.idToken.toString();

 

Geoff

View solution in original post

13 REPLIES 13

Geoff_T
Mega Sage

Hello,

You do not need to define JSONParser. You can simply parse responseStr like:

var parsed = JSON.parse(responseStr);

 

Geoff

If I am remove JSONparser, then getting an error as Cannot read property "idToken" from undefined

Can you paste in the response so that I can copy it - then I can parse it for you with the code you need.

Geoff

Here is the response.

 

{"message":"Successfully Logged in","token":{"idToken":"eyJhbGciOiJSUzI1NiIsImtpZCI6ImFiMGNiMTk5Zjg3MGYyOGUyOTg5YWI0ODFjYzJlNDdlMGUyY2MxOWQiLCJ0eXAiOiJKV1QifQ.eyJuYW1lIjoiTWljaGFlbCBTY290dCIsInJvbGUiOiJhZG1pbiIsImlzcyI6Imh0dHBzOi8vc2VjdXJldG9rZW4uZ29vZ2xlLmNvbS9jYXJlYXItcGxheWdyb3VuZCIsImF1ZCI6ImNhcmVhci1wbGF5Z3JvdW5kIiwiYXV0aF90aW1lIjoxNjIzMDU3NTY2LCJ1c2VyX2lkIjoiSFdDYk9MN3I0MGFiRWhSc0JydXNhUnNId2d3MiIsInN1YiI6IkhXQ2JPTDdyNDBhYkVoUnNCcnVzYVJzSHdndzIiLCJpYXQiOjE2MjMwNTc1NjYsImV4cCI6MTYyMzA2MTE2NiwiZW1haWwiOiJtaWNoYWVsQG9mZmljZS5jb20iLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsImZpcmViYXNlIjp7ImlkZW50aXRpZX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