JSON NULLs - Mailing list pgsql-hackers

From David E. Wheeler
Subject JSON NULLs
Date
Msg-id A62DDF0A-81DF-4988-9440-F038B46D60D6@justatheory.com
Whole thread Raw
Responses Re: JSON NULLs  (Merlin Moncure <mmoncure@gmail.com>)
List pgsql-hackers
Hackers,

While playing with Andrew’s JSON enhancements, I noticed this:
   david=# select * From json_each_as_text('{"baz": null}'::json);    key | value    -----+-------    baz | null

It is returning 'null'::text there, not NULL::text. I had expected the latter, because otherwise it's not possible to
tellthe difference between '{"foo": null}' and '{"foo": "null"}'. 

But then I noticed that this seems to be true for JSON NULLs in general:
   david=# select 'null'::json::text IS NULL;    ?column?    ----------    f

Again, I expected a NULL there. I recognize that JSON NULLs are not the same as SQL NULLs, but if there is no way to
tellthe difference, well, it’s annoying. 

I see that '"null"'::json::text resolves to '"null"'::text, so that’s one way to deal with it. But since
json_each_as_textreturns values as text, not quoted JSON values, maybe *it* should return JSON NULLs as SQL NULLs? 

Thanks,

David




pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: palloc unification
Next
From: Andres Freund
Date:
Subject: Re: palloc unification