mardi 18 février 2020

Append multiple dummy objects to json array with jq

Lets say this is my array :

[
  {
    "name": "Matias",
    "age": "33"
  }
]

I can do this :

echo "$response" | jq '[ .[] | select(.name | test("M.*"))] | . += [.[]]'

And it will output :

[
  {
    "name": "Matias",
    "age": "33"
  },
  {
    "name": "Matias",
    "age": "33"
  }
]

But I cant do this :

echo "$response" | jq '[ .[] | select(.name | test("M.*"))] | . += [.[] * 3]'
jq: error (at <stdin>:7): object ({"name":"Ma...) and number (3) cannot be multiplied

I need to extend an array to create a dummy array with 100 values. And I cant do it. Also, I would like to have a random age on the objects. ( So later on I can filter the file to measure performance of an app .




Aucun commentaire:

Enregistrer un commentaire