Forum Discussion

Ludo15101966's avatar
Ludo15101966
Contributor
7 years ago

JsonSlurper

Hello,

I was previously using the groovy class JsonSlurper to edit a json before sending it to REST web services

 

seems that the class is no more supported

 

what is the workaround to do the same thing

- create a json object using template string

- modifying the json structure

- sending the json string to web service

thank you

regards

 

 

  • MoUddin's avatar
    MoUddin
    7 years ago

    Have you imported JsonSlurper into your script with:

    import groovy.json.JsonSlurper

     

    Mo

  • Hi there,

     

    As far as I can tell JsonSlurper is still supported by groovy

    Could you give any more information on your issue?

     

    Mo

    • Ludo15101966's avatar
      Ludo15101966
      Contributor

      Hi, thanks for your help

      my groovy code is very simple

      ...

      def slurper = new JsonSlurper()
      def object = slurper.parseText(jsonAsText)
      object.name = context.servername1

       

      I receive now an error

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script14.groovy: 36: unable to resolve class JsonSlurper @ line 36, column 15. def slurper = new JsonSlurper() ^ org.codehaus.groovy.syntax.SyntaxException: unable to resolve class JsonSlurper @ line 36, column 15. at

       

      I saw in a post a ne class jsonUtils introduced in 2.4, I can parse json but not modify it

       

      Do you have an idea ?

       

      • MoUddin's avatar
        MoUddin
        Contributor

        Have you imported JsonSlurper into your script with:

        import groovy.json.JsonSlurper

         

        Mo