Skip to content

Instantly share code, notes, and snippets.

@VimleshS
Forked from joar/jq-insert-var.sh
Created January 20, 2022 08:20
Show Gist options
  • Save VimleshS/9e42e009cd3aa48b6723a80a8f8e294f to your computer and use it in GitHub Desktop.
Save VimleshS/9e42e009cd3aa48b6723a80a8f8e294f to your computer and use it in GitHub Desktop.

Revisions

  1. @joar joar revised this gist Oct 28, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion jq-insert-var.sh
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ echo '{"hello": "world"}' | jq --arg foo bar '. + {foo: $foo}'
    # "foo": "bar"
    # }

    # Change a field
    # Override field value
    echo '{"hello": "world"}' | jq --arg foo bar '. + {hello: $foo}'
    {
    "hello": "bar"
  2. @joar joar revised this gist Oct 28, 2015. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion jq-insert-var.sh
    Original file line number Diff line number Diff line change
    @@ -12,4 +12,11 @@ echo '{"hello": "world"}' | jq --arg foo bar '. + {hello: $foo}'
    }
    # {
    # "hello": "bar"
    # }
    # }

    # Concat and add
    echo '{"hello": "world"}' | jq --arg foo bar '. + {hello: ("not" + $foo)}'
    # {
    # "hello": "world",
    # "foo": "notbar"
    # }
  3. @joar joar revised this gist Oct 28, 2015. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions jq-insert-var.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,15 @@
    # Add field
    echo '{"hello": "world"}' | jq --arg foo bar '. + {foo: $foo}'
    # {
    # "hello": "world",
    # "foo": "bar"
    # }

    # Change a field
    echo '{"hello": "world"}' | jq --arg foo bar '. + {hello: $foo}'
    {
    "hello": "bar"
    }
    # {
    # "hello": "bar"
    # }
  4. @joar joar revised this gist Oct 28, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion jq-insert-var.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    echo '{"hello": "world"}' | jq --arg foo bar '. | . + {foo: $foo}'
    echo '{"hello": "world"}' | jq --arg foo bar '. + {foo: $foo}'
    # {
    # "hello": "world",
    # "foo": "bar"
  5. @joar joar created this gist Oct 28, 2015.
    5 changes: 5 additions & 0 deletions jq-insert-var.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    echo '{"hello": "world"}' | jq --arg foo bar '. | . + {foo: $foo}'
    # {
    # "hello": "world",
    # "foo": "bar"
    # }