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

JsonOutput / Groovy JSON Builder do not escape special characters in map keys

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.2, 2.3.6, 2.4.0
    • 2.4.2
    • JSON
    • Linux, Ubuntu Trusty 64 Bit, OpenJDK 7

    Description

      When creating JSON from maps, the keys are not properly quoted. The result ist invalid JSON.

      Example code:

      def o = [
        'a "Test"': "test1",
        'test2': 'Test "2"'
      ]
      
      println JsonOutput.toJson(o)
      println JsonOutput.prettyPrint(JsonOutput.toJson(o))
      

      Example code output:

      {"a "Test"":"test1","test2":"Test \"2\""}
      

      Caught: groovy.json.JsonException: Lexing failed on line: 1, column: 6, while reading 'T', no possible valid JSON value or punctuation could be recognized.

      As you see, 'Test "2"' is being quoted correctly, but 'a "Test"' is not. The pretty printing fails parsing the invalid JSON in the second println line.
      This happens with JsonBuilder as well.

      Attachments

        Issue Links

          Activity

            People

              melix Cédric Champeau
              thomasritter Thomas Ritter
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: