Show HN: Transform a CSV into a JSON and vice versa
21–30 of 111 posts
Re: Show HN: Transform a CSV into a JSON and vice versa
#22 mlr --c2j cat documents.csv > documents.jsonl
Converts a CSV file to a JSONL fileRe: Show HN: Transform a CSV into a JSON and vice versa
#23Slightly OT: I've realized that CSVs are dramatically more information-dense than the equivalent JSON, and actually make a pretty reasonable API response format if your dataset is large and fits into the tabular shape. They can be a fraction of the size, mainly because keys aren't duplicated for every item.
Re: Show HN: Transform a CSV into a JSON and vice versa
#24Slightly OT: I've realized that CSVs are dramatically more information-dense than the equivalent JSON, and actually make a pretty reasonable API response format if your dataset is large and fits into the tabular shape. They can be a fraction of the size, mainly because keys aren't duplicated for every item.
Shouldn’t really matter too much if the response is being compressed. If you’re rendering the table in the DOM, the response size is the least of your issues.
Where it becomes relevant is if each record is stored as a separate document so you can't just compress them all together. Compressing each record separately won't eliminate the duplication, so you're better off with either a columnar format (like a typical database) or a schema-based format (like protobuf.)
Re: Show HN: Transform a CSV into a JSON and vice versa
#25CSV is more of a rumor than a standard, plus JSON can have a tree structure. It is a fun idea to think about and may be useful in some narrow cases, but will fail in almost all but those most trivial of structures.
> CSV is more of a rumor than a standard This reminds me of something my boss at a previous job would say: "I am morally opposed to CSV." Why? Because we worked at an NLP company, where we would frequently have tabular data featuring commas, which means if we used CSV we'd have a lot of overhead involving quoting all our CSV data. Instead my boss preferred TSV (T = tab) as our preferred tabular data format, which was…
Re: Show HN: Transform a CSV into a JSON and vice versa
#26CSV is more of a rumor than a standard, plus JSON can have a tree structure. It is a fun idea to think about and may be useful in some narrow cases, but will fail in almost all but those most trivial of structures.
> CSV is more of a rumor than a standard This reminds me of something my boss at a previous job would say: "I am morally opposed to CSV." Why? Because we worked at an NLP company, where we would frequently have tabular data featuring commas, which means if we used CSV we'd have a lot of overhead involving quoting all our CSV data. Instead my boss preferred TSV (T = tab) as our preferred tabular data format, which was…
Re: Show HN: Transform a CSV into a JSON and vice versa
#27Earlier quoted context omitted.
It would be much nicer for the consumer to just de-dupe the keys in your json than to serve an annoying format like CSV. Your JSON could basically be a matrix with a header row, there's nothing forcing you to duplicate keys. { header: [...columnNames], rows: [...values2DArray]}
Make rows 1 dimensional. You don’t need the second dimension, it’s implied by header length. Once you do this, the JSON gzips down to about the same size as CSV, according to the last time I tested this IIRC.
Re: Show HN: Transform a CSV into a JSON and vice versa
#28Earlier quoted context omitted.
Shouldn’t really matter too much if the response is being compressed. If you’re rendering the table in the DOM, the response size is the least of your issues.
This is the real answer. All of the other answers are suggesting various changes to the JSON structure to eliminate key repetition, but this is irrelevant under compression. Where it becomes relevant is if each record is stored as a separate document so you can't just compress them all together. Compressing each record separately won't eliminate the duplication, so you're better off with either a columnar format (lik…
So you just have an array of arrays. Or even a huge array and every X elements, it’s a new record.
If each one has 2 keys,
[
{
key1: ‘a’,
key2: ‘b’
},
{
key1: ‘a’,
key2: ‘b’
}
]
Can become, [
[
‘a’,
‘b’
],
[
‘a’,
‘b’
]
]
Or just every 2 will be a new record, [
‘a’,
‘b’,
‘a’,
‘b’
]Re: Show HN: Transform a CSV into a JSON and vice versa
#29Earlier quoted context omitted.
> CSV is more of a rumor than a standard This reminds me of something my boss at a previous job would say: "I am morally opposed to CSV." Why? Because we worked at an NLP company, where we would frequently have tabular data featuring commas, which means if we used CSV we'd have a lot of overhead involving quoting all our CSV data. Instead my boss preferred TSV (T = tab) as our preferred tabular data format, which was…
I always try to use ascii char 31 (unit seperator) if I'm computationally generating csvs for shunting around data internally.
Re: Show HN: Transform a CSV into a JSON and vice versa
#30https://codepen.io/theprojectsomething/pen/OwppWW
Note: click the Toggle Info to read the "spec" (groan) :)