Customer Portal

How to suppress empty array and null item in a array in JSONWriter output

Comments 3

  • Avatar
    jzhu
    0
    Comment actions Permalink
    Some examples.

    (1) Empty array:
    "phoneNumbers" : []

    (2) Empty item in an array:
    "phoneNumbers": [{"phoneNumber": "0123456789", "type":""},{"phoneNumber": "0789123456", "type":"mobile"}]

    (3) Empty item in an array:
    "address": {"lines":["line1","","line3"], "city": "London"}
  • Avatar
    Pedro Vazquez Rosario
    0
    Comment actions Permalink
    Hi jzhu,

    The reason "write null element" doesn't work in your case is because it considering the value as and empty string and not a null value. Thus, you will need to use a Reformat component prior to writing the JSON file to change from empty string to null. I have taken the liberty of including some graphs based on the examples you provided. In the case of the empty array, I have yet to find a way to suppress it, but I will keep looking and send you and example as soon as possible.
  • Avatar
    Pedro Vazquez Rosario
    0
    Comment actions Permalink
    Hi jzhu,

    I have looked into trying to suppress the empty array, unfortunately as of right now JSONWriter is not able to suppress it. We have created a improvement request for the JSONWriter to suppress empty arrays, which you can keep track of here.

Please sign in to leave a comment.