akheron / jansson

C library for encoding, decoding and manipulating JSON data
http://www.digip.org/jansson/
Other
3.05k stars 809 forks source link

How to distinguish "present but empty object for key" from "key absent" #561

Closed laf0rge closed 3 years ago

laf0rge commented 3 years ago

I'm assuming the following JSON input:

{ 'scope': {'scope_plmn:': {} } }

How can I distinguish the two cases:

It seems that json_object_get(scope_obj, "scope_plmn") returns NULL in both cases. I don't understand why. An empty object is prefectly legal, and json_object() itself returns an empty object.

I can iterate over the "scope" object using the iterator functions and then see that the "scope_plnn" key is actually present, and that it is of type JSON_OBJECT. So why does json_object_get() not simply return that object?

What is the logic here? How is the user application expected to distinguish those two cases? Any help is greatly appreciated.

laf0rge commented 3 years ago

nevermind, I only now realized that the key "source_plmn:" contains an extraneous colon.