我有一个在Bash中卷曲的javascript变量。
URL为https://hygoshop.com/collections/best-sellers/products/mystical-moon-lamp
它看起来像这样:
var meta = {"product":{"id":1460229996586,"vendor":"ZINUO Factory Store","type":"","variants":[{"id":12924116893738,"price":2499,"name":"Mystical Moon Lamp - XXS - 7.8 CM\/3.1 INCH","public_title":"XXS - 7.8 CM\/3.1 INCH","sku":""},{"id":12924066201642,"price":2999,"name":"Mystical Moon Lamp - XS - 9 CM\/3.5 INCH","public_title":"XS - 9 CM\/3.5 INCH","sku":""},{"id":12924068036650,"price":4399,"name":"Mystical Moon Lamp - S - 12 CM\/4.7 INCH","public_title":"S - 12 CM\/4.7 INCH","sku":""},{"id":12865176829994,"price":5499,"name":"Mystical Moon Lamp - M - 15 CM\/5.9 INCH","public_title":"M - 15 CM\/5.9 INCH","sku":""},{"id":12924067250218,"price":7499,"name":"Mystical Moon Lamp - L - 18 CM\/7.1 INCH","public_title":"L - 18 CM\/7.1 INCH","sku":""},{"id":12865176862762,"price":8899,"name":"Mystical Moon Lamp - XL - 20 CM\/7.9 INCH","public_title":"XL - 20 CM\/7.9 INCH","sku":""}]},"page":{"pageType":"product","resourceType":"product","resourceId":1460229996586}};
如何在bash中提取所有这些变量(在meta变量中),以便可以将其写入文本文件并使用jq进行解析?
谢谢。
答案 0 :(得分:0)
您可能正在寻找这样的东西:
curl -H "Accept: application/json" -X GET "https://hygoshop.com/collections/best-sellers/products/mystical-moon-lamp" | jq ...
或者,如果您坚持使用curl
命令并想在使用jq
之前去除变量:
curl ... | sed 's/^[^{]*//;s/;$//' | jq ...