Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

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

@fkluthe

Description

@fkluthe

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions