question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JsonException when parsing single value JSON

See original GitHub issue

According to RFC 7159, “A JSON text is a sequence of tokens. The set of tokens includes six structural characters, strings, numbers, and three literal names.” As such, TRUE, FALSE, NULL, Strings, and numbers should be acceptable JSON even if the response does not start with { or [. For example, a RESTFul response of false is valid JSON.

However, RestAssured fails when parsing such single token JSON responses. Below is the exception trace:

groovy.json.JsonException: A JSON payload should start with an openning curly brace '{' or an openning square bracket '['.
Instead, 'false' was found on line: 1, column: 1
       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
       at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
       at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
       at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
       at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
       at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)
       at io.restassured.internal.path.json.ConfigurableJsonSlurper.parse(ConfigurableJsonSlurper.groovy:114)
       at io.restassured.internal.path.json.ConfigurableJsonSlurper$parse.callCurrent(Unknown Source)
       at io.restassured.internal.path.json.ConfigurableJsonSlurper.parseText(ConfigurableJsonSlurper.groovy:83)
       at 

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:9

github_iconTop GitHub Comments

5reactions
MonaAgrawalcommented, Feb 8, 2021

Any update on this issue, I am facing the same issue.

1reaction
johanhalebycommented, Dec 5, 2017

REST Assured is using an old json parser (JsonSlurper) from Groovy. I tried the new one and then it works but then I get a lot of other tests that fails. Need to look into it more. Thanks for pointing out, I actually didn’t know this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSONException: Value of type java.lang.String cannot be ...
So the solution was that i tried to substring my json String one by one and ... catch (JSONException e) { Log.e("JSON Parser",...
Read more >
SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
JSON.parse() parses a string as JSON. This string has to be valid JSON and will throw this error if incorrect syntax was encountered....
Read more >
JSONObject - Android Developers
Creates a new JSONObject with name/value mappings from the JSON string. ... Throws. JSONException, if the parse fails or doesn't yield a JSONObject...
Read more >
Exceptions - JSON for Modern C++
An operation of a JSON Patch document must contain exactly one "op" ... [json.exception.parse_error.105] parse error: operation value 'foo' is invalid ...
Read more >
JsonParser (JSON Documentation) - Oracle Help Center
Returns a String for the name in a name/value pair, for a string value or a number value. This method should only be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found