我有这个结构
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选项。我看不到为什么这不起作用谢谢您的帮助
这将是:
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
如果您只想要值(不带标题):
[.[]] | @tsv
如果您还想要标题:
(keys_unsorted, [.[]]) | @tsv