SQLite Forum

Join columns, separate items with with \n, and export as geojson?
Login
> Join some columns so that I only get a single column through SELECT, where each original item should have a \\n added so they're still separate

This is what the [group_concat] function does, as long as you convert the columns to rows.

To create JSON-encoded text, use the [JSON functions]:

~~~sql
SELECT json_object(
    'geometry', json_object(
        'coordinates', json_array(longitude, latitude),
        'type', 'Point'),
    'properties', json_object(
        'description', (SELECT group_concat(p, char(10))
                        FROM (SELECT 'email=' || email AS p
                              UNION ALL
                              SELECT 'www='   || www
                              UNION ALL
                              SELECT 'phone=' || phone)),
        'name', name),
    'type', 'Feature')
FROM camping;
~~~

[group_concat]: https://www.sqlite.org/lang_aggfunc.html#groupconcat
[JSON functions]: https://www.sqlite.org/json1.html