使用 grep 获取 json 中括号内的内容

使用 grep 获取 json 中括号内的内容

我有以下 json 数据

"url": "https://www.etsy.com/listing/812858182/59ft-x-84ft-moroccan-rug-mrirt-rug-beni?utm_source=etsymeter&utm_medium=api&utm_campaign=api",
  "num_favorers": 26,
  "views": 69,
  "sku": [
    "Atlas115"
  ],
  "is_vintage": false
},
{
  "title": "Custom Beni ourain Authentic Moroccan rug, Berber carpet,rug, Handmade rug, Beni ourain style, Area rug, Tapis berbere, Berber rugs",
  "tags": [
    "beni ourain rug",
    "neutral rug",
    "moroccan rug",
    "boho rug",
    "kitchen rug",
    "area rugs",
    "shag rug",
    "Custom made rug",
    "Beniourain 5x7",
    "5x7 Beni ourain",
    "8x10 ft 4x6 ft",
    "5x8 4x6",
    "5x7 8x10 9x12"
  ],
  "url": "https://www.etsy.com/listing/887996258/custom-beni-ourain-authentic-moroccan?utm_source=etsymeter&utm_medium=api&utm_campaign=api",
  "num_favorers": 63,
  "views": 436,
  "sku": [
    "GG002"

因此我使用 grep 来获取所有 sku 参数,它显示了这个空结果:

  "sku": [
  "sku": [
  "sku": [
  "sku": [
  "sku": [
  "sku": [
  "sku": [
  "sku": [],

正如您在第一个代码“sku”中看到的:[“Atlas115”],我想获取所有 sku 参数及其属性

答案1

在尝试了 jq 的不同情况后,我找到了正确的 jq 命令来获取正确的数据,命令如下:

jq '.results[] | {sku}'

如果您想要获取多个字段:

jq '.results[] | {title,sku}'

相关内容