-
-
Save yannmh/9da37691ac90c64895217cb2f23818c6 to your computer and use it in GitHub Desktop.
Add a field to an object with JQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add field | |
echo '{"hello": "world"}' | jq --arg foo bar '. + {foo: $foo}' | |
# { | |
# "hello": "world", | |
# "foo": "bar" | |
# } | |
# Override field value | |
echo '{"hello": "world"}' | jq --arg foo bar '. + {hello: $foo}' | |
{ | |
"hello": "bar" | |
} | |
# { | |
# "hello": "bar" | |
# } | |
# Concat and add | |
echo '{"hello": "world"}' | jq --arg foo bar '. + {hello: ("not" + $foo)}' | |
# { | |
# "hello": "world", | |
# "foo": "notbar" | |
# } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment