13 Matching Annotations
- Dec 2022
- Oct 2022
-
stedolan.github.io stedolan.github.io
-
Multiplying two objects will merge them recursively: this works like addition but if both objects contain a value for the same key, and the values are objects, the two are merged with the same strategy.
Unfortunately, it doesn't merge/concatenate arrays. Sometimes that's what you want (you want the 2nd value to override the 1st but sometimes not.
If you want it to concatenate instead, here are some workarounds:
-
https://stackoverflow.com/questions/53661930/jq-recursively-merge-objects-and-concatenate-arrays
-
If you only need/want to concatenate for some fixed list of keys, you could do it more simply like this (but could get repetitive to repeat for each key you want it for):
⟫ jq -n '[{hosts: ["a"]}, {hosts: ["b"]}] | .[]' | jq -s '.[0] * .[1] * {hosts: (.[0].hosts + .[1].hosts)}' { "hosts": [ "a", "b" ] }
-
-
-
stackoverflow.com stackoverflow.com
-
github.com github.com
-
jq -s '.[0] * .[1]' $config_file $local_config_file
Tags
Annotators
URL
-
- Oct 2021
-
raspberrypi.stackexchange.com raspberrypi.stackexchange.com
-
jq '.profile.exit_type= "Normal" | .profile.exited_cleanly = true' ~pi/.config/chromium/Default/Preferences
-
- Mar 2021
-
stackoverflow.com stackoverflow.com
-
Colin D asks how to preserve the JSON structure of the array, so that the final output is a single JSON array rather than a stream of JSON objects. The simplest way is to wrap the whole expression in an array constructor:
-
-
stedolan.github.io stedolan.github.io
-
jq uses the Oniguruma regular expression library, as do php, ruby, TextMate, Sublime Text, etc, so the description here will focus on jq specifics.
Tags
Annotators
URL
-
- Dec 2020
-
blog.differentpla.net blog.differentpla.net
Tags
Annotators
URL
-
- Nov 2020
-
serverfault.com serverfault.com
-
systemctl show --no-page iptables \ | jq --slurp --raw-input \ 'split("\n") | map(select(. != "") | split("=") | {"key": .[0], "value": (.[1:] | join("="))}) | from_entries'
-
Decode of jq command:
-
- May 2020
-
stackoverflow.com stackoverflow.com
-
Gitlab API can be used
-