akheron / jansson

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

Unpacking optional value #583

Open lameventanas opened 3 years ago

lameventanas commented 3 years ago

I want to unpack a JSON that has an optional key. When the key is present, the value may be a string or null. I was able to achieve the optional key with "{s?:s}", but I can't unpack this when the value is null. I have tried with "{s?:s?}".

Then I found this: https://github.com/akheron/jansson/blob/0dffb4284e7872c6e26956ad85fe127ba77220dc/test/suites/api/test_unpack.c#L379

Under this line there's a test for unpacking optional key, and another for optional value, but both have the same format specifier. So I'm confused now.