Let's evaluate the parsing of each:

http://jsfiddle.net/brandonscript/Y2dGv/

var json1 = '{}';
var json2 = '{"myCount": null}';
var json3 = '{"myCount": 0}';
var json4 = '{"myString": ""}';
var json5 = '{"myString": "null"}';
var json6 = '{"myArray": []}';

console.log(JSON.parse(json1)); // {}
console.log(JSON.parse(json2)); // {myCount: null}
console.log(JSON.parse(json3)); // {myCount: 0}
console.log(JSON.parse(json4)); // {myString: ""}
console.log(JSON.parse(json5)); // {myString: "null"}
console.log(JSON.parse(json6)); // {myArray: []}

The tl;dr here:

The fragment in the json2 variable is the way the JSON spec indicates null should be represented. But as always, it depends on what you're doing -- sometimes the "right" way to do it doesn't always work for your situation. Use your judgement and make an informed decision.


JSON1 {}

This returns an empty object. There is no data there, and it's only going to tell you that whatever key you're looking for (be it myCount or something else) is of type undefined.


JSON2 {"myCount": null}

In this case, myCount is actually defined, albeit its value is null. This is not the same as both "not undefined and not null", and if you were testing for one condition or the other, this might succeed whereas JSON1 would fail.

This is the definitive way to represent null per the JSON spec.


JSON3 {"myCount": 0}

In this case, myCount is 0. That's not the same as null, and it's not the same as false. If your conditional statement evaluates myCount > 0, then this might be worthwhile to have. Moreover, if you're running calculations based on the value here, 0 could be useful. If you're trying to test for null however, this is actually not going to work at all.


JSON4 {"myString": ""}

In this case, you're getting an empty string. Again, as with JSON2, it's defined, but it's empty. You could test for if (obj.myString == "") but you could not test for null or undefined.


JSON5 {"myString": "null"}

This is probably going to get you in trouble, because you're setting the string value to null; in this case, obj.myString == "null" however it is not == null.


JSON6 {"myArray": []}

This will tell you that your array myArray exists, but it's empty. This is useful if you're trying to perform a count or evaluation on myArray. For instance, say you wanted to evaluate the number of photos a user posted - you could do myArray.length and it would return 0: defined, but no photos posted.

Answer from brandonscript on Stack Overflow
Top answer
1 of 8
589

Let's evaluate the parsing of each:

http://jsfiddle.net/brandonscript/Y2dGv/

var json1 = '{}';
var json2 = '{"myCount": null}';
var json3 = '{"myCount": 0}';
var json4 = '{"myString": ""}';
var json5 = '{"myString": "null"}';
var json6 = '{"myArray": []}';

console.log(JSON.parse(json1)); // {}
console.log(JSON.parse(json2)); // {myCount: null}
console.log(JSON.parse(json3)); // {myCount: 0}
console.log(JSON.parse(json4)); // {myString: ""}
console.log(JSON.parse(json5)); // {myString: "null"}
console.log(JSON.parse(json6)); // {myArray: []}

The tl;dr here:

The fragment in the json2 variable is the way the JSON spec indicates null should be represented. But as always, it depends on what you're doing -- sometimes the "right" way to do it doesn't always work for your situation. Use your judgement and make an informed decision.


JSON1 {}

This returns an empty object. There is no data there, and it's only going to tell you that whatever key you're looking for (be it myCount or something else) is of type undefined.


JSON2 {"myCount": null}

In this case, myCount is actually defined, albeit its value is null. This is not the same as both "not undefined and not null", and if you were testing for one condition or the other, this might succeed whereas JSON1 would fail.

This is the definitive way to represent null per the JSON spec.


JSON3 {"myCount": 0}

In this case, myCount is 0. That's not the same as null, and it's not the same as false. If your conditional statement evaluates myCount > 0, then this might be worthwhile to have. Moreover, if you're running calculations based on the value here, 0 could be useful. If you're trying to test for null however, this is actually not going to work at all.


JSON4 {"myString": ""}

In this case, you're getting an empty string. Again, as with JSON2, it's defined, but it's empty. You could test for if (obj.myString == "") but you could not test for null or undefined.


JSON5 {"myString": "null"}

This is probably going to get you in trouble, because you're setting the string value to null; in this case, obj.myString == "null" however it is not == null.


JSON6 {"myArray": []}

This will tell you that your array myArray exists, but it's empty. This is useful if you're trying to perform a count or evaluation on myArray. For instance, say you wanted to evaluate the number of photos a user posted - you could do myArray.length and it would return 0: defined, but no photos posted.

2 of 8
281

null is not zero. It is not a value, per se: it is a value outside the domain of the variable indicating missing or unknown data.

There is only one way to represent null in JSON. Per the specs (RFC 4627 and json.org):

2.1.  Values

A JSON value MUST be an object, array, number, or string, or one of
the following three literal names:

  false null true

Discussions

null values in JSON values
When return type in Controller is JObject the values in the json object are displayed null. But If I am trying to print on Console the out put is Ok. How to deal with this? More on learn.microsoft.com
🌐 learn.microsoft.com
2
0
July 30, 2022
How to encode a value as JSON null
Can someone help me figure out how to encode a value as null? For example, say I have a record rec = {v1 : String, v2 : Float} Say, value of v2 can be missing. When I send JSON to the server, I want to encode v2 as nu… More on discourse.elm-lang.org
🌐 discourse.elm-lang.org
5
0
June 15, 2019
Best Practices to send for Empty Values of a JSON API?
On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge. If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options: Limiting your involvement with Reddit, or Temporarily refraining from using Reddit Cancelling your subscription of Reddit Premium as a way to voice your protest. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/learnprogramming
16
16
April 22, 2024
cjson - What is the JSON Standard for an empty string or null variable? - Stack Overflow
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 h... More on stackoverflow.com
🌐 stackoverflow.com
🌐
OutSystems
outsystems.com › forums › discussion › 60155 › send-json-null-value
Send JSON NULL value | OutSystems
April 27, 2020 - I am trying to send a NULL value in a (JSON) REST request but I get bad-method when trying with OutSystems, doing the same with PostMan results in the desired field being set to NULL. I tried to send NULL as a string but the services on the other end sees that as just a string containing the ...
🌐
JSON Schema
json-schema.org › understanding-json-schema › reference › null
JSON Schema - null
When a schema specifies a type of null, it has only one acceptable value: null. It's important to remember that in JSON, null isn't equivalent to something being absent.
🌐
JSON Formatter
jsonformatter.org › 17d6c3
NULL
It helps to validate JSON online with Error Messages.
Find elsewhere
🌐
Progress
docs.progress.com › bundle › corticon-deployment-71 › page › How-to-pass-null-values-in-a-JSON-request.html
How to pass null values in a JSON request
August 26, 2025 - Skip to main contentSkip to search · Powered by Zoomin Software. For more details please contactZoomin
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 948655 › null-values-in-json-values
null values in JSON values - Microsoft Q&A
July 30, 2022 - Force the use of Newtonsoft.Json for serialization by converting the JObject to a string before returning it.
🌐
Elm
discourse.elm-lang.org › learn
How to encode a value as JSON null - Learn - Elm
June 15, 2019 - Can someone help me figure out how to encode a value as null? For example, say I have a record rec = {v1 : String, v2 : Float} Say, value of v2 can be missing. When I send JSON to the server, I want to encode v2 as nu…
🌐
Albertmoreno
albertmoreno.dev › posts › json-api-design-to-allow-null-values-or-not-an-in-depth-look-at-the-pros-and-cons
JSON API Design: To Allow Null Values or Not? An In-depth Look at the Pros and Cons :: Hi! 👋 I'm Albert
February 12, 2023 - Null values are a special marker used in databases and programming languages to indicate the absence of a value. In JSON APIs, null values are represented as a null key-value pair, such as “field_name”: null.
🌐
IBM
ibm.com › docs › en › baw › 24.0.x
Handling JSON null and empty arrays and objects
January 20, 2025 - Handling null and empty arrays and objects used in JSON data is described.
🌐
Quora
quora.com › How-do-you-pass-a-null-value-in-JSON
How to pass a null value in JSON - Quora
Answer: In addition to strings, numbers, arrays, and objects, JSON supports three special values: true, false, and null. This page is really everything you need to know about JSON syntax. (Effective usage is another story…) https://www.json.org/json-en.html It is possible your intended question...
🌐
Reddit
reddit.com › r/learnprogramming › best practices to send for empty values of a json api?
r/learnprogramming on Reddit: Best Practices to send for Empty Values of a JSON API?
April 22, 2024 -

What do you choose? Getting lots of conflicting answers.

  1. Null

  2. Undefined (Omitted from JSON)

  3. Empty of that type?

    1. String = ""

    2. Number = 0

    3. Boolean = false

    4. Array = []

    5. Object = {}

CMS JSON API to be consumed by JS Framework Frontend

🌐
JSON for Modern C++
json.nlohmann.me › api › basic_json › is_null
is_null - JSON for Modern C++
#include <iostream> #include <nlohmann/json.hpp> using json = nlohmann::json; int main() { // create JSON values json j_null; json j_boolean = true; json j_number_integer = 17; json j_number_unsigned_integer = 12345678987654321u; json j_number_float = 23.42; json j_object = {{"one", 1}, {"two", 2}}; json j_array = {1, 2, 4, 8, 16}; json j_string = "Hello, world"; json j_binary = json::binary({1, 2, 3}); // call is_null() std::cout << std::boolalpha; std::cout << j_null.is_null() << '\n'; std::cout << j_boolean.is_null() << '\n'; std::cout << j_number_integer.is_null() << '\n'; std::cout << j_number_unsigned_integer.is_null() << '\n'; std::cout << j_number_float.is_null() << '\n'; std::cout << j_object.is_null() << '\n'; std::cout << j_array.is_null() << '\n'; std::cout << j_string.is_null() << '\n'; std::cout << j_binary.is_null() << '\n'; }
🌐
Google Groups
groups.google.com › g › jsonschema › c › mD6GDca4zN8
How to allow None (null) for fields in JSON Schema?
This is because you require fb_id be a string, and null is not a string. If you also want to allow null values for fb_id, you can set its schema to {"type": ["string", "null"]} ... -- You received this message because you are subscribed to the Google Groups "jsonschema - An implementation of JSON Schema for Python" group.
🌐
ConvertCSV
convertcsv.com › csv-to-json.htm
CSV To JSON Converter
Generate JSON via Template - Using our template engine, easily customize your JSON output NEW · Automatic detection of numeric values, logical values, and nulls
🌐
InterSystems
community.intersystems.com › post › json-null-properties
JSON - NULL Properties | InterSystems Developer Community
I.e., type "boolean" converts ObjectScript numeric expressions into JSON false/true values and type "null" converts an ObjectScript %String into a JSON string *except* that the empty string is converted to the JSON null value.
🌐
Calhoun
calhoun.io › how-to-determine-if-a-json-key-has-been-set-to-null-or-not-provided
How to determine if a JSON key has been set to null or not provided - Calhoun.io
When the key is not provided, and the value is implicitly null. Unfortunately (or fortunately?), that isn’t how Go, or really any typed languages work. We don’t declare a struct (or class) and magically lose a field when it isn’t defined.