Closed mando7 closed 1 year ago
Sorry, not supported.
thank you for your answer, maybe in a next version ?
Hi @mando7,
I could achieve something close to what you want :
==> test.csv <==
id,age,gender
1,39,M
2,25,M
3,36,F
csvtk gather -k item -v value -Ff "*" test.csv |
csvtk summary -s';' -g item -f value:collapse |
csvtk del-header | csvtk transpose | csvtk csv2json
1) Use csvtk gather
on all fields (= -Ff "*"
) to create key-value pairs
item value
------ -----
id 1
age 39
gender M
id 2
age 25
gender M
id 3
age 36
gender N
2) Use csvtk summary
to group by item
and collapse all values of each "field" into a ';'-delimited list (all id
values, all age
values ...)
(this step can also be achieve through csvtk fold -s';' -f item -v value
, but not sure what difference it makes)
item value:collapse
------ --------------
age 39;25;36
gender M;M;N
id 1;2;3
3) Remove useless header, transpose back and convert to JSON
[
{
"id": "1;2;3",
"age": "39;25;36",
"gender": "M;M;F"
}
]
Hope this helped ! Have a nice day, Felix.
Hi, Is it possible to obtain this output ?
From csv
To json column array minify
OR json column array
Thank you in advance for your reply.