Skip to content

Instantly share code, notes, and snippets.

@olive42
Created January 31, 2017 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olive42/56cdd11f5bd5dd74c0f27d0f1ba69858 to your computer and use it in GitHub Desktop.
Save olive42/56cdd11f5bd5dd74c0f27d0f1ba69858 to your computer and use it in GitHub Desktop.
JsonSlurper parses wrong JSON
Groovy Shell (2.4.7, JVM: 1.8.0_121)
Type ':help' or ':h' for help.
---------------------------------------------------------------------------------------------------------------------------------------
groovy:000> import groovy.json.JsonSlurper
===> groovy.json.JsonSlurper
groovy:000> import groovy.json.JsonParserType
===> groovy.json.JsonSlurper, groovy.json.JsonParserType
groovy:000> parser = new JsonSlurper().setType(JsonParserType.INDEX_OVERLAY)
===> groovy.json.JsonSlurper@36060e
groovy:000> parser.parseText('''\
groovy:001> {
groovy:002> "name": "web",
groovy:003> "tags": ["windows"],
groovy:004> },
groovy:005> ''')
===> [name:web, tags:[windows]]
groovy:000> wrongJson = '''\
groovy:001> {
groovy:002> "name": "web",
groovy:003> "tags": ["windows"],
groovy:004> },
groovy:005> '''
===> {
"name": "web",
"tags": ["windows"],
},
groovy:000> parser.parseText(wrongJson)
===> [name:web, tags:[windows]]
groovy:000>
@olive42
Copy link
Author

olive42 commented Jan 31, 2017

% jsonlint-php <<EoF
{
"name": "web",
"tags": ["windows"],
},
EoF
Parse error on line 3:
...tags": ["windows"],},
---------------------^
Expected: 'STRING' - It appears you have an extra trailing comma

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment