What is the JSON Standard for an empty string or null variable?

Austen Stone picture Austen Stone · Aug 25, 2017 · Viewed 16.6k times · Source

I'm building an application that parses a JSON template and then replaces the values of the objects with new data. My question is what is the standard way to represent empty data in JSON?

This is how I'm handling this right now:

  • an empty string is represented as " "
  • an empty int/float/double/bool/etc. is represented as NULL

Is this correct?

Answer

Jester picture Jester · Aug 25, 2017

It should be pretty straight forward.

{
  "Value1": null, 
  "Value2": null,
}

Null represents a null-able datatype so your business layer needs then to know if that is an int, double, string ...