4 Replies Latest reply: Apr 9, 2014 4:13 AM by shanghaiet RSS

    How do you retrieve the value?

    shanghaiet

      Hi There,

       

      XML request is:

       

      <?xml version="1.0" encoding="utf-8"?>

      <payload>

        <region>

          <__type>Category:#Test.XYZ.Framework.Categorization</__type>

          <Extension></Extension>

          <Id></Id>

          <Name>

            <en></en>   

          </Name>   

        </region>

      </payload>

       

      I did an XML to JSON conversion on the above and stored the value of "en" node under "Name" in an attribute named "payload.region.Name.en" by extracting using JSON path filter - using "$.payload.region.Name.en".

       

      But, when I print the value of the attribute, it is printing as "null". Any idea why? I was expecting "" as I do not want the string null to be send as the value for "en".

       

      Regards,

      ET

        • 1. Re: How do you retrieve the value?
          StefanOEG

          Hi,

           

          The XML to JSON filter does actually converty empty value into the string "null" in the JSON and when you read it out with the path it actually reads the string "null". It does look a bit flawed in my opinion and I recommend creating a support case for it..

           

          But a solution for you!

           

          Create a script filter (JavaScript) after you have read the parameter and do this:

           

          function invoke(msg)

          {

              var att = msg.get("payload.region.Name.en");

           

           

             if (att == "null") {

                msg.put("payload.region.Name.en", "");

              }

           

           

              return true;

          }

           

          It will just replace null with an empty string!

           

          Cheers,

          Stefan

          • 2. Re: How do you retrieve the value?
            shanghaiet

            Thank You Stefan for the reply and for the solution offered.

             

            But then, I am being bombarded with a huge xml which has hundreds of such elements having multiple json batches (Gave the scenario to illustrate my problem) . Not sure whether I can go ahead with a function in this case. Do we have other ways? How about reading content.body in a file and replacing all "null" with ""?

             

            Regards,

            ET

            • 3. Re: How do you retrieve the value?
              StefanOEG

              The problem is that after you have done the XML to JSON conversion the data stored in content.body is in the format of com.vordel.mime.JSONBody (JSONBody (Vordel SDK)) so you can't just do a find and replace on the strings on the document.

               

              You can build a JavaScript that will iterate over all the nodes and replace the null values with "", but that solution is a lot more complex to build and a bit to time consuming for me to help out with here.

               

              Cheers,

              Stefan

              • 4. Re: How do you retrieve the value?
                shanghaiet

                Got this one sorted out by unmarshalling the json expression path as org.json.simple.JSONObject

                 

                Cheers,

                ET