Home > Mobile >  Java how to represent empty Integer in JSON
Java how to represent empty Integer in JSON

Time:10-12

I have to represent in JSON null Integer in this way score: . Show name of the attribute and empty space if Integer is null. Now if Integer is null, then JSON doesn't show attribute. Is it possible to do it with Integer?

CodePudding user response:

It is not possible to leave a property value empty in JSON.

The possible value type for the fields are:

enter image description here

Set your variable to something distinctable like -1 or something.

CodePudding user response:

JSON represents data as name/value pairs. There must be a value present if the name is present. See JSON.org for the complete syntax.

A null can be represented by specifying null ...

{name: "Steve", score : null}

... or by omitting the name 'score' from the JSON ...

{name : "Steve"}
  • Related