Because tWriteJSONField generates an xml, then converts it to JSON using json-lib. Your null value will be converted to an empty xml node <STATE_PROVINCE/>
, and json-lib, having no context of this node, will assume it is a parent node with no children, instead of an empty text (null notion is already far at this point).
Here is what happens in short:
package test.json;
public class JSONTest {
public static void main(String[] args) {
net.sf.json.xml.XMLSerializer s = new net.sf.json.xml.XMLSerializer();
s.clearNamespaces();
s.setSkipNamespaces(true);
s.setForceTopLevelObject(true);
net.sf.json.JSON json = s.read("<?xml version=\"1.0\" encoding=\"ISO-8859-15\"?>" +
"<org>" +
"<STATE_PROVINCE/>" +
"</org>"
);
System.out.println(json.toString());
}
}
Result:
{"org":{"STATE_PROVINCE":[]}}
A dirty solution is to use attributes instead of nodes in your tWriteJSONField, but it will prefix your properties with @. So after this component you put a tReplace, search "\"@"
, replace with "\""
, uncheck whole word, check global expression. Your final JSON will have no property if null.