-1

i have the following json data

"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"

So i used grep to fetch all sku parameter and it show me this empty result :

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

As you see in the first code "sku": [ "Atlas115" ], i would like to fetch all sku parameter with their attributes

newbiline
  • 1
  • 1
  • 3
    The JSON code seems to be missing some bits. But if the top level is just a `[ ... ]` block, you could use `jq` for that, something like `jq -c '.[].sku'` – Erwin Jun 29 '22 at 04:37
  • i did use jq but it's not yet the right command i did try jq '.results[].sku' it did give me just sku values but if want to append another parameter such as tags it goes wrong in this way jq '.results[].tags.sku' i dont know why – newbiline Jun 29 '22 at 05:14
  • You can get more than one field of a JSON array with `jq` like this: `jq '.[] | .title, .sku'` – Peter Zhabin Jun 29 '22 at 06:12
  • it did not work but i did try this one | jq '.results[1].title , .results[1].tags , .results[1].views' – newbiline Jun 29 '22 at 06:18
  • You do not provide entire file, JSON you show is broken. – Romeo Ninov Jun 29 '22 at 09:16

1 Answers1

0

after trying different cases of jq i came cross the right jq command for fetching the right data here is the command :

jq '.results[] | {sku}'

if you want to fetch more than field :

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