-1

When I try to put "null" string value to a JSONObject using the API JSONObject.element(key, value), this API converts this "null" string value to null.

API used: net.sf.json.JSONObject, JAR version: json-lib-2.3-jdk15

JSONObject jObj = new JSONObject();
jObj.element("msg", null);

For the given code snippet, the output is

{"msg":null}

However, it should be

{"msg":"null"}
Sudhir Ojha
  • 3,247
  • 3
  • 14
  • 24
Saurabh Arora
  • 80
  • 1
  • 9
  • You don't use a string null in your code – GalAbra Jun 21 '19 at 06:22
  • For some reason, the null string as typed by the user is passed from the UI, this is being validated and sent back to the browser as a JSON. – Saurabh Arora Jun 21 '19 at 06:24
  • Possible duplicate of [How can I put key with null value in net.sf.json.JSONObject?](https://stackoverflow.com/questions/18932188/how-can-i-put-key-with-null-value-in-net-sf-json-jsonobject) – GalAbra Jun 21 '19 at 06:27
  • Nope, that is related to putting null key, this is related to "null" value – Saurabh Arora Jun 21 '19 at 06:29

1 Answers1

0

Never mind, I have handled this at the UI side. The JSONObject API doesn't support the requirement.

Saurabh Arora
  • 80
  • 1
  • 9