Quantcast
Viewing all articles
Browse latest Browse all 522

jq: delete element from array

I have this JSON file and want to delete an element from an array:

{"address": "localhost","name": "local","vars": {"instances": ["one","two"    ]  }}

I am using this command:

jq 'del(.vars.instances[] | select(index("one")))' data.json

The output is:

{"address": "localhost","name": "local","vars": {"instances": ["two"    ]  }}

So it works as expected, but only with jq v1.6. With jq v1.5 I get this error:

jq: error (at data.json:20): Invalid path expression near attempt to access element 0 of [0]

So what am I doing wrong? Is this a bug or a feature of v1.5? Is there any workaround to get the same result in v1.5?

Thanks in advance

Vince


Viewing all articles
Browse latest Browse all 522

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>