Json Storage does not allow null

0 votes
When storing any document which contains nulls using the StorageService the server returns the error code 500 and an error that the json string was invalid.
 
This behaviour should be possible, as stated on Json.org "A value can be a string in double quotes, or a number, or true or false or null, or an object or an array. These structures can be nested."
 
An example of a json document with nulls would be:
{
    "requiredField":"Some value must be here",
    "someOptionalField":null
}
Or in an array:
{
    "sampleArray":["test",null,"hello","world",null]
}

 

The problem occurs when trying to insert a document or update/save it when it has any JSONObject.NULL value stored.
asked Nov 23, 2017 in Java by Gal Peric (22 points)

1 Answer

0 votes
Hi Gal,

 

Apologies for getting late back to you.

It is only because of null values stored in JSON document.  It's NoSQL DB and it works in a different way compared to RDBMS. the document {"age":21,"name":"john Doe"} is same as {"age":21,"name":"john Doe";"address":null}. We will suggest you instead of storing the key's as null better to not store the key at all this improves the performance of your reads/updates against the DB.

 

Let me know if it helps or you need any other help from my side.

 

Regards,

Himanshu Sharma
answered Nov 27, 2017 by hs00105 (2,005 points)
I have not considered that yet, and it definitely helps with some use cases, but this solution does not quite work for the problem I am having.

Consider an array of a fixed size (for example 4). It is ordered and we need to know whether or not the third index is null or if it instead contains an object.

If I were to *not* save the null values I would end up with an incorrect array because instead of it being ["value", "value", null, "value"] it would be ["value", "value", "value"].

You are right in that the two examples you gave are the same! But JSON as a NoSQL database format should still be able to save null values (at least in an array of values), as that is part of its specification.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...