I've this structure
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
}
I want to make it tsv with jq, but jq says:
jq: error (at <stdin>:1): object ({"products_...) cannot be tsv-formatted, only array
I can't see why
the full command I'm passing is :
jq '@tsv' file.json
I tried -c or -r and -R options with no luck. I can't see why this doesn't work Thanks for your help
If you just want the values (without headers):
[.[]] | @tsv
If you want the headers as well:
(keys_unsorted, [.[]]) | @tsv
It would be:
jq -r 'to_entries|map(.value)|@tsv' file.json
to_entries
transforms the input into:
[
{
"key": "base_price_mw",
"value": 249.99
},
{
"key": "best_offer_base_price",
"value": 280.06
},
{
"key": "best_offer_nature",
"value": 11
},
...
]
... we get only the values from that using map(.value)
and pass that to @tsv
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With