Mastodon Mastodon - jq snippets
 logo
  • Home 
  • Tags 
  • Blog posts 
  1. Home
  2. Blog posts
  3. jq snippets

jq snippets

Posted on August 21, 2021  (Last modified on July 11, 2024) • 1 min read • 86 words
Cli   Tools: Jq   Tools   Json  
Cli   Tools: Jq   Tools   Json  
Share via

Delete any object which contains a "keyname": "keyvalue" pair anywhere in the JSON:

cat x.json| jq 'del(..|select(objects and .keyname == "keyvalue"))'

If keyname contains a dash ("-"), use one of those notations:

cat x.json | jq 'del(..|select(objects and .["key-name"] == "keyvalue"))'
cat x.json | jq 'del(..|select(objects and ."key-name" == "keyvalue"))'

Delete all objects anywhere that contain a certain key:

cat x.json | jq 'del(..|select(objects and .key?)'

Delete a certain key from all objects everywhere:

cat x.json | jq 'del(..|.response?)'

Useful sources:

  • Fabian Keller
  • jq docs
  • A StackOverflow post I forgot
 Extract parts of a git repo as new one
Lexoffice API notes 
In case you want to follow me

Here are some links. The further to the right, the less active.

           
(c) Axel Bock | Powered by Hinode.
Link copied to clipboard
Code copied to clipboard