JsonException when parsing single value JSON
See original GitHub issueAccording 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:
- Created 6 years ago
- Comments:9
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Any update on this issue, I am facing the same issue.
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.