简体   繁体   English

jQ:在Windows上将json转换为tsv

[英]jQ: transforming json to tsv on Windows

I am using jq on a windows machine and I have the following data: 我在Windows计算机上使用jq,并且有以下数据:

{"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". 我可以使用“ .a”或“ .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. 与CSV相比,TSV是一种更简单的格式。 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. 只要确保使用原始输出-r选项即可。

[ .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 . jq的最新版本(例如1.5rc1-可通过https://github.com/stedolan/jq/releases获得 )包括一个名为@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. 在4月15日,对jq进行了增强,以便@tsv将产生有效的tsv(每个有效数组一行),例如,如果输入字符串包含制表符,换行符或NUL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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