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

JSON.parse() just greps the first json object in given source-string and returns. #8

Open
fkluthe opened this issue Aug 10, 2018 · 2 comments

Comments

@fkluthe
Copy link

fkluthe commented Aug 10, 2018

See https://github.com/grails-plugins/grails-plugin-converters/blob/master/src/main/groovy/grails/converters/JSON.java#L249
and final Object value = new JSONTokener(source).nextValue();

Eg:

        def s = '{"foo":"bar"}{"baz":true}'
        def json = JSON.parse(s)
        json.toString() == '{"foo":"bar"}'

I find this behavior confusing, i was expecting rather a ConverterException than a silent ignore.

A situation where this can get nasty, is in integration specs when you do something like json = JSON.parse(controller.response.contentAsString as String) and in the related controller, more then one response was rendered like render(contentType: 'application/json', text: someJson.toString()) (by accident, eg missing return after render)

@jameskleeh
Copy link
Contributor

The converters API is deprecated in favor of JSON views. That means that in general we won't be making changes to this library

@fkluthe
Copy link
Author

fkluthe commented Aug 14, 2018

Ok, too bad, but fair enough.

Any recommendation how to validate a JSON string with Groovy?

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

2 participants