Re: [sqlite] Ideas for optional json fields?

2016-09-26 Thread Eric Grange
Nice solution and works like a charm, thanks Clemens! On Mon, Sep 26, 2016 at 4:22 PM, Clemens Ladisch wrote: > Eric Grange wrote: > > I am generating a json with json_object() function, and I would like to > > omit the null or default fields from the output json > > SELECT

Re: [sqlite] Ideas for optional json fields?

2016-09-26 Thread Clemens Ladisch
Eric Grange wrote: > I am generating a json with json_object() function, and I would like to > omit the null or default fields from the output json SELECT (SELECT json_group_object(key, value) FROM json_each(json_object('field1', field1, 'field2', field2)) WHERE value IS NOT NULL)

Re: [sqlite] Ideas for optional json fields?

2016-09-26 Thread Eric Grange
Using coalesce on the value produces the field with the JSON, with an empty string (or whatever it was coalesced again). What I really would like to get is {"field1":"value"} rather than {"field1":"value","field2":null} or {"field1":"value","field2":""} I also tried setting the field name to

Re: [sqlite] Ideas for optional json fields?

2016-09-26 Thread R Smith
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