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

JsonSlurper does not handle backslash

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.8.0
    • 1.8.1, 1.9-beta-1
    • JSON
    • None
    • Gentoo Linux (amd64) / sun-jdk 1.6.0_26

    Description

      The JsonSlurper does not appear to handle backslash characters () even if they have been properly escaped.

      Using this sample pieced together from the Groovy 1.8.0 Release Notes:

      import groovy.json.*
      
      def json = new JsonBuilder()
      
      json.person {
          name "Guill\\aume"
          age 33
          pets "Hector", "Felix"
      }
      
      def jsonstring = json.toString()
      println jsonstring
      
      def slurper = new JsonSlurper()
      def doc = slurper.parseText(jsonstring)
      
      println doc
      

      $ groovy json.groovy

      {"person":{"name":"Guill\\aume","age":33,"pets":["Hector","Felix"]}}
      Caught: groovy.json.JsonException: Expected a value on line: 1, column: 69.
      But got an unterminated object.
              at json.run(json.groovy:15)
      

      Have tried this with 1.8.0, 1.8.1 Snapshot (2011-06-13), 1.9.0 Snapshot (2011-06-13)

      Attachments

        1. json.groovy
          0.3 kB
          Matt Michalowski

        Activity

          People

            guillaume Guillaume Sauthier
            mattmichalowski Matt Michalowski
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: