简体   繁体   中英

jQ: transforming json to tsv on Windows

I am using jq on a windows machine and I have the following data:

{"a":"Person","birthDay":"12","deathDay":"15", ...}
{"a":"Person","birthDay":"13","deathDay":"16", ...}
...

And I would like to have a tab separated file format:

Person   12   15
Person   13   16

I can get the values with ".a" or ".birhtDay". But how can I get all values and separate them through a tab?

Kind regards, Snafu

TSV is fortunately a simpler format compared to CSV. Assuming the values will not have newlines or tabs, you just need to build up each of the rows of data you want in the file and print them out separating values by tabs. Just make sure you use the raw output -r option.

[ .a, .birthDay, .deathDay ] | join("\t")

Recent versions of jq (eg 1.5rc1 -- available via https://github.com/stedolan/jq/releases ) include a filter named @tsv .

On April 15, jq was enhanced so that @tsv will produce valid tsv (one line per valid array), eg if an input string contains tabs, newlines, or NULs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM