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

JSONWriter input port (not port 0) maps to an array in JSON. Some times the array is empty, or some items in the array is empty. How do I suppress the empty array or empty empty items in the array of the output JSON file?

For empty items in the array, tried “Write null element”, and it did not seem to work.

I am using CloverETL designer 4.3.

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”}

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.

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.