empty or null for objects per json standard ?

3,084 views
Skip to first unread message

Ivan Voronov

unread,
Nov 3, 2014, 3:10:42 PM11/3/14
to jackso...@googlegroups.com
Dear Colleagues,

1) In looking at the JSON standard
from http://www.json.org, the standard says that 
"An object structure is represented as a pair of curly bracket tokens surrounding zero or more name/value pairs. "
It means that the object can not be null. Correct?

Actually
{
    "obj": {}
}
is a valid JSON here http://jsonlint.com/

Unfortunately, my Java guy who uses jackson for interfacing with a core written in C/C++, says that "it is impossible to generate / parse empty object ({}), only null is acceptable for objects". (Actually our C/C++ core does not understand null-objects).

Could you please advise 
1) Is empty object ({}) is a standard for objects per json standard ?
2) Can jackson generate empty object for objects and null for other values?

Thank you,

Best regards,
Ivan

Tatu Saloranta

unread,
Nov 3, 2014, 5:41:36 PM11/3/14
to jackso...@googlegroups.com
On Mon, Nov 3, 2014 at 12:10 PM, Ivan Voronov <ivor...@gmail.com> wrote:
Dear Colleagues,

1) In looking at the JSON standard
from http://www.json.org, the standard says that 
"An object structure is represented as a pair of curly bracket tokens surrounding zero or more name/value pairs. "
It means that the object can not be null. Correct?

Actually
{
    "obj": {}
}
is a valid JSON here http://jsonlint.com/


As is:

{
    "obj" : null
}

I think you are trying to read too much into description here. While it is true that Javascript value "null" is not an object, this has little relevance to question of how to represent Java values.

In Java, nulls are not typed. Null is a lack of a thing. It's not an Object, any more than in JSON.

But all this means is that the natural serialization of Java null is JSON null (and vice versa).
I don't see much benefit in using "{ }" as null marker for general case, especially given that List/array types (serialized as JSON Arrays) and scalar types (Strings, Numbers, Booleans) would also get serialized as "{ }" (as there may or may not be a way to know what intended type for actual value would be).

 
Unfortunately, my Java guy who uses jackson for interfacing with a core written in C/C++, says that "it is impossible to generate / parse empty object ({}), only null is acceptable for objects". (Actually our C/C++ core does not understand null-objects).

Could you please advise 
1) Is empty object ({}) is a standard for objects per json standard ?

I think { } is the notation for objects with no properties, but "null" is the natural mapping of Java nulls (null references).
 
2) Can jackson generate empty object for objects and null for other values?


No, there is no customization to output "{ }" instead of null for specific class of objects.
It is possible to suppress writing of 'null' values for properties, but not for changing how null is output.

Hope this helps,

-+ Tatu +-

 
Thank you,

Best regards,
Ivan

--
You received this message because you are subscribed to the Google Groups "jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
To post to this group, send email to jackso...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ivan Voronov

unread,
Dec 3, 2014, 1:44:42 PM12/3/14
to jackso...@googlegroups.com
Dear Tatu & ALL,

Thank you for the reply!

Can you confirm that statement 
"JSON's value called null can be set on any type of data including arrays, objects, number and boolean types"
is 100% MATCH the standard http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf. It is unclear (and unevident) from the standard.

Please advise,

Thank you again,

Best regards,
Ivan

Tatu Saloranta

unread,
Dec 3, 2014, 6:15:44 PM12/3/14
to jackso...@googlegroups.com
I don't see anything unclear in that statement so I don't know how I could help here.

But if you want to ask people who work on JSON standard, you could ask on a json mailing list, either IETF one, or json.org one.

-+ Tatu +-

Reply all
Reply to author
Forward
0 new messages