3 ms·
Another approach to this is wrapping the query in a `copy to stdout` statement (either in the .sql or with a tiny wrapper), then converting the CSV to JSON. If
by mhd 7y ago
Another approach to this is wrapping the query in a `copy to stdout` statement (either in the .sql or with a tiny wrapper), then converting the CSV to JSON.
If you're doing the processing with jq and don't want to install any other tools than that, a jq csv -> json script should be about 10 lines.
- Piskvorrr 7y agoEw ew ew, that's an ugly hack if ever there was one. Anything involving CSV is guaranteed to have a nasty bite, as soon as you get CSV's "control characters" (which ones? Ha, trick question! There's about 6 sets of them in common use, almost but not entirely different.) in the mix. TL;DR: CSV brittle, do not want.
- mhd 7y agoBelieve me, I could sing songs of pain about "CSV", its various delimiters, escapes and encodings. Makes you almost wish for the horrible format garbage that is Excel… But in this case you're not messing with some arbitrary CSV, you're generating it yourself right before converting into another horrible format. Slightly better.