我有这个结构
file.json:
{
"base_price_mw": 249.99,
"best_offer_base_price": 280.06,
"best_offer_nature": 11,
"best_offer_promo_price": 247.35,
"best_offer_shiping_price": 0,
"best_shop_id": 2004,
"best_shop_name": "Stuff",
"cat_id": 69,
"grey_dot": true,
"is_exclusivity": null,
"is_favorite": false,
"is_new": false,
"is_topsales": false,
"manufacturer_id": 58,
"name": "my product name",
"nature_mw": 11,
"note": "0.0000",
"offers_count": 11,
"offers_min_price": 233.21,
"products_ids": 30671,
"promo_price_mw": 249.99,
"status": 1
}
我想用jq制作tsv,但是jq说:
jq: error (at <stdin>:1): object ({"products_...) cannot be tsv-formatted, only array
我不明白为什么
我传递的完整命令是:
jq '@tsv' file.json
我尝试了-c或-r和-R选项没有运气。我不明白为什么这不起作用 谢谢你的帮助
答案 0 :(得分:5)
这将是:
jq -r 'to_entries|map(.value)|@tsv' file.json
to_entries
将输入转换为:
[
{
"key": "base_price_mw",
"value": 249.99
},
{
"key": "best_offer_base_price",
"value": 280.06
},
{
"key": "best_offer_nature",
"value": 11
},
...
]
...我们只使用map(.value)
获取该值并将其传递给@tsv
答案 1 :(得分:3)
如果您只想要值(不带标题):
[.[]] | @tsv
如果你也想要标题:
(keys_unsorted, [.[]]) | @tsv