Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7253

groovy.json.JsonSlurper cannot parse JSON standard compliant JSON

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Not A Problem
    • 2.3.8
    • None
    • JSON
    • None
    • all ( tested on Linux x86_64, Ubuntu 14.4 & RHEL-6.6 )

    Description

      groovy.json.JsonSlurper exits with an error when parsing valid JSON :

      $ groovy -e ' import groovy.json.*; println new JsonSlurper().parseText('"'"'"V":"\/"'"'"');'
      14-Jan-2015 14:23:55 org.codehaus.groovy.runtime.m12n.MetaInfExtensionModule newModule
      WARNING: Module [groovy-nio] - Unable to load extension class [org.codehaus.groovy.runtime.NioGroovyMethods]
      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      script_from_command_line: 1: unexpected char: '\' @ line 1, column 66.
         JsonSlurper().parseText('"V":"\/"');
                                       ^
      1 error
      

      AFAICS, escaped chars ARE supported by the JSON Specification , as reported by
      http://www.json.org :

      "A string is a sequence of zero or more Unicode characters, wrapped in double
      quotes, using backslash escapes."

      Any occurrence of a back-slash escape sequence in a JSON string makes groovy fail
      to parse the JSON, which is unfortunate, since my company's Microsoft web
      application server translates all occurrences of the '/' character in JSON responses
      to '\/', so we cannot use groovy to parse any of its JSON output.

      Any chance of a standards-compliant JSON parser in groovy anytime soon, or do I
      need to write my own ?

      Attachments

        1. groovy_bug.groovy
          0.1 kB
          Jan van Doorn

        Activity

          People

            Unassigned Unassigned
            jvd Jan van Doorn
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: