How to remove an array element with jq?

Regarding the second part of Paul Ericson’s question

But more generically, I’m trying to understand how jq would allow for selective array element control. Maybe next time I want to delete array elements 1,3,5 and 11.

To delete elements 1,3,5 and 11 just use

del(
    .Array[1,3,5,11]
)

but in general you can use a more sophisticated filter as the argument to del. For example, this filter removes the elements within .Array whose .foobar2 key is "barfoo2":

del(
    .Array[]
  | select(.foobar2 == "barfoo2")
)

producing in this example

{
  "blah0": "zeroblah",
  "Array": [
    {
      "blah1": [
        "key1:val1"
      ],
      "foobar0": "barfoo0",
      "foobar1": "barfoo1"
    }
  ]
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)