datasette-json-html
datasette-json-html copied to clipboard
Skip nulls or empty href values in arrays?
Consider this query, with this SQL:
select
json_array(
json_object(
'href',
'https://simonwillison.net/',
'label',
'Simon Willison'
),
case
when 'hi' = 'hello' then json_object(
'href',
'https://www.python.org/',
'label',
'Python'
)
end,
json_object(
'href',
'',
'label',
'Empty href'
)
) as links
The links don't render due to the null as the second item and the empty href value in the third.
I was trying to put together a query that rendered links for column values I had at hand but some may be missing. There's no doubt a way to extend the query to turn the columns into a subquery so I could use json_group_array but that would be a bit more complicated.
Would skipping null items and/or items with empty href values be worthwhile?