我有这个结构
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
}
Run Code Online (Sandbox Code Playgroud)
我想用jq使其成为tsv,但是jq表示:
jq: error (at <stdin>:1): object ({"products_...) cannot be tsv-formatted, only array
Run Code Online (Sandbox Code Playgroud)
我不明白为什么
我传递的完整命令是:
jq '@tsv' file.json
Run Code Online (Sandbox Code Playgroud)
我没有运气就尝试了-c或-r和-R选项。我看不到为什么这不起作用谢谢您的帮助
我需要获取 mysql 表的内容,该表具有一些将数据存储为 JSON 数组的字段,并将其提取到另一个数据库表中。我需要为此使用 REST API,它会返回 JSON 格式的记录。出于性能原因,我需要该输出为选项卡选项卡返回。因此我使用jq的@tsv。
这非常有效,直到它遇到一个内部有 JSON 数组的字段,然后 jq 抱怨“数组在 csv 行中无效”。
这是一个 JSON 示例
{
"records": [
{
"id": 1,
"metadata": {
"description": null,
"width": 0,
"height": 0,
"secondaryColor": "#fff",
"callToAction": [
{
"link": "/truc.html",
"value": "nice",
"colors": {
"primary": "transparent;",
"secondary": "transparent;"
}
}
]
},
"parent": null
}
]
}
Run Code Online (Sandbox Code Playgroud)
我想要以下结果
1 null 0 0 #fff [ { "link": "/truc.html", "value": "nice", "colors": { "primary": "transparent;", "secondary": "transparent;" } } ] null
Run Code Online (Sandbox Code Playgroud)
所以基本上我希望数组完好无损,但只是在一行中返回 …