Try using JSONObject.NULL instead of null if you are using org.json.
Link to the documentation .
change
I tried to create a json object with a null value, something like this.
JSONObject jsonObject = new JSONObject(); jsonObject.put("Test", JSONObject.NULL);
and the output created by printing was {"Test": null}
So, I think it will do the magic for you. :)
Dave ranan
source share