On 2016/09/26 11:15 AM, Eric Grange wrote:
Hi,
I am generating a json with json_object() function, and I would like to
omit the null or default fields from the output json (for compacity reasons)
When there is only one such field, I have used a "case when" like in
select
case when field2 is null then
json_object('field1', field1)
else
json_object('field1', field1, 'field2', field2)
end
...
but when there are multiple such optional fields, this approach becomes
unwieldy.
I'm not experienced playing with the JSON extension much, but the
solution that feels correct to me would be:
select json_object('field1', COALESCE(field1,'""'), 'field2',
COALESCE(field2,'""'))
or some such variant that produces the correct output...
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users