Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DocumentContext#json() Returns Invalid JSON When A JSON Object Is Parsed #217

Closed
ryanlevell opened this issue Apr 6, 2016 · 4 comments
Closed

Comments

@ryanlevell
Copy link

When a JSON object is parsed, DocumentContext#json() returns invalid JSON, possibly java.util.Map#toString().
When a JSON array is parsed, DocumentContext#json() returns returns valid JSON.

Java

// json object
System.out.println("JSON Object: " + JsonPath.parse("{a: \"123\"}").json());
// json array
System.out.println("JSON Array: " + JsonPath.parse("[{a: \"123\"}]").json());

Console

JSON Object: {a=123} # Map#toString()
JSON Array: [{"a":"123"}] # Valid JSON
@ryanlevell ryanlevell changed the title DocumentContext#json() Returns Non-valid JSON When A JSON Object Is Parsed DocumentContext#json() Returns Invalid JSON When A JSON Object Is Parsed Apr 6, 2016
@ryanlevell
Copy link
Author

As a workaround, ReadContext#jsonString() works as expected for JSON arrays and objects.

@kallestenflo
Copy link
Contributor

This is by design. The .json() method returns the JSON document as parsed by the JsonProvider The .jsonString() returns the JSON document as a String.

@ryanlevell
Copy link
Author

Thanks for the clarification.

@jochenberger
Copy link
Contributor

@kallestenflo close this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants