sfgroups sfgroups - 3 months ago 33
Groovy Question

groovy json parsing error

I get request return this JSON string.

{ success: true, uuid: '2e11b13d-fc7d-4939-a311-c42f673b7ba6'}


when I parse this with groovy, it giving below error message.

Here is the code

def jsonSlurper = new JsonSlurper()
def object = jsonSlurper.parseText (responseBody)


groovy.json.JsonException: expecting '}' or ',' but got current char 's' with an int value of 115

The current character read is 's' with an int value of 115
expecting '}' or ',' but got current char 's' with an int value of 115
line number 1
index number 1
{success:true,uuid:'2e11b13d-fc7d-4939-a311-c42f673b7ba6'}
.^


how can I fix this error in groovy?

thanks
SR

Answer

Your json is not syntactically correct. Try to parse this one:

{ "success": true, "uuid": "2e11b13d-fc7d-4939-a311-c42f673b7ba6" }

You can read more about json format here

Comments