jq以选项卡格式获取所有值

时间:2018-10-22 11:29:09

标签: json jq

我正在尝试将json转换为制表符格式的数据:

{"level":"INFO", "logger":"db", "msg":"connection successful"}
{"level":"INFO", "logger":"server", "msg":"server started"}
{"level":"INFO", "logger":"server", "msg":"listening on port :4000"}
{"level":"INFO", "logger":"server", "msg":"stopping s ervices ..."}
{"level":"INFO", "logger":"server", "msg":"exiting..."}

像这样:

INFO   db       connection successful
INFO   server   server started
INFO   server   listening on port 4000
DEBUG  server   stopping s ervices ...
INFO   server   exiting...

我已经尝试过jq -r ' . | to_entries[] | "\(.value)"',但这会在单独的行上打印每个值。

1 个答案:

答案 0 :(得分:1)

假设键总是相同的顺序,那么您可以摆脱:

jq -r '[.[]]|@tsv'

无论如何,最好使用@tsv