Skip to content

Instantly share code, notes, and snippets.

@lktslionel
Last active January 15, 2021 17:50
Show Gist options
  • Save lktslionel/3e24db96ef73b7a19bb5b5f56177dc07 to your computer and use it in GitHub Desktop.
Save lktslionel/3e24db96ef73b7a19bb5b5f56177dc07 to your computer and use it in GitHub Desktop.
Tips and tricks with JQ

Transformations

// input.json
[
  {
    "label": "A",
    "value": "1"
  },
  {
    "label": "B",
    "value": "2"
  }
]

Transform to { .label = .value }

cat input.json | jq -r 'map({ (.label): .value }) | add'

Transform to --name=.label --value=.value

jq -r '.Parameters | .[] |  "--name=\"" + .Name + "\" --value=\"" + .Value + "\""'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment