Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-48148

writeJson step to serialize to string variable

      the writeJSON step currently only allows for serialization of a variable object (map, list etc) to file, but for certain operations (such as executing an adhoc curl), it would be nice if you could serialize to a string and then use that as part of the call.

      For example:

      sh (script: "curl -s http://localhost/rpc -d '{ \"field1\": 123 }' -H 'Content-Type: application/json'")

      Could be re-written as:

      def bodyMap = readJSON text: '{}'
      bodyMap.field1 = 123 
      def jsonStr = writeJSON json: bodyMap
      sh (script: "curl -s http://localhost/rpc -d '${jsonStr}' -H 'Content-Type: application/json'")

      Granted you could just serialize to file and then pass that file to the curl command.

          [JENKINS-48148] writeJson step to serialize to string variable

          I'd also love to see this feature implemented, especially that readJSON can read from both file and string variable, would be great if writeJSON would be able to write to string variable.

          Dmitry Bigunyak added a comment - I'd also love to see this feature implemented, especially that readJSON can read from both file and string variable, would be great if writeJSON would be able to write to string variable.

          Basil Peace added a comment -

          Looks like current version accepts returnText parameter.

           

          BTW, why use readJSON to construct empty object?
          def bodyMap = readJSON text: '{}'
          Generic map should work:
          def bodyMap = [:]

          Basil Peace added a comment - Looks like current version accepts  returnText parameter.   BTW, why use readJSON to construct empty object? def bodyMap = readJSON text: '{}' Generic map should work: def bodyMap = [:]

            rsandell rsandell
            chriswhite199 Chris White
            Votes:
            6 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: