3 Replies Latest reply on Apr 7, 2021 8:32 AM by User6392 N

    How to remove {} in with empty arrays

    User6392 N Seasoned Veteran

      Hi All,

      I have an output from my ICRT process like below:

      {

          "Response": {

              "ABC": [

                  {

                      "x1": " XX",

                      "x2": "43TRG",

                      "x3": "0",

                      "x4": " RGFD",

                      "ABC12": [

                          {

                              "Y1": "W4645U6Y",

                              "Y2": "3",

                              "Y3": "0"

                          }

                      ],

                      "ABC34": [

                          {}

                      ]

                  }

              ]

          }

      }

       

      The requirement is if an array is empty, then the array should return only [] and not [{}].

      In the above example, ABC34 is an empty array but in output it has [{}] . But it should have only this [].

      So Expected Output should be:

      {

          "Response": {

              "ABC": [

                  {

                      "x1": " XX",

                      "x2": "43TRG",

                      "x3": "0",

                      "x4": " RGFD",

                      "ABC12": [

                          {

                              "Y1": "W4645U6Y",

                              "Y2": "3",

                              "Y3": "0"

                          }

                      ],

                      "ABC34": [ ]

                  }

              ]

          }

      }

       

      NOTE: I am using a process object to return my output

        • 1. Re: How to remove {} in with empty arrays
          Rich Bateman Seasoned Veteran

          Hello-

          Have you tried this expression on your output?

           

          util:parseXML(util:toXML(your_field))

           

          When I run that on your sample payload this is the response:

          {
            "Output": [
              {
                "Response": {
                  "ABC": [
                    {
                      "ABC12": [
                        {
                          "Y1": "W4645U6Y",
                          "Y2": "3",
                          "Y3": "0"
                        }
                      ],
                      "ABC34": [
                        null
                      ],
                      "x1": " XX",
                      "x2": "43TRG",
                      "x3": "0",
                      "x4": " RGFD"
                    }
                  ]
                }
              }
            ]
          }
          
          • 2. Re: How to remove {} in with empty arrays
            User6392 N Seasoned Veteran

            Hi Rich,

             

            Thanks for your response. I did try the solution suggested by you. But i am getting this error :

             

             

            Could you please show the assignment of output you are doing in process?

             

             

             

            Thanks

            • 3. Re: How to remove {} in with empty arrays
              Prakash Jain Guru

              Hi,

               

              You may also try to use replace function to {} with nothing like replace($variable, '{}','')

               

               

              Thanks,

              Prakash Jain