simonw/sqlite-transform

jsonsplit command

Closed this issue · 6 comments

A command for turning fields with commas in into JSON arrays would be handy

sqlite-transform jsonsplit my.db mytable tags

Default to , as the delimiter but allow --delimiter ";" option

If that column has foo, bar it will be rewritten as ["foo", "bar"]

Mainly useful to use with Datasette's facet-by-array mechanism.

I tried this on a column with values like 123,455,112 and got back ["123", "455", "112"] - which made me think that it would be nice to have a --type option which lets you convert the values to floats or integers.

I ran this twice on the same column and got weird results!

["[137", "858]"]

I think this should fail with an warning, and users should be able to over-ride that warning with --force.

That's a bad feature. I started coding it up and got to the warning message:

Skipped 5 values because they appear to already be JSON arrays. Use --force to apply to those as well

But then I realized that if you do this:

$ sqlite-transform jsonsplit blah.db mytable col
# see that warning... so run
$ sqlite-transform jsonsplit blah.db mytable col --force

You'll mangle all of the data that WAS correctly processed the first time you ran that command!

So I'm going to drop the array warning idea entirely.