I want to use jq to add new objects into the following JSON string.
Here is the test json_string:
json_string="$(cat <<'END'{"hello": {"foo": {"version": "1.1.1" } },"world": {"bar": {"version": "2.2.2" } }}END)"Here is the hello:
# hello="$(jq -r ".hello" <<< "$json_string")"# echo "$hello"{"foo": {"version": "1.1.1" }}Here is the world:
# world="$(jq -r ".world" <<< "$json_string")"# echo "$world"{"bar": {"version": "2.2.2" }}Here is the full JSON string including the newly added combined:
# full="$(jq -r ".+= combined ${hello} ${world}" <<< "$json_string")"jq: error: syntax error, unexpected '{', expecting $end (Unix shell quoting issues?) at <top-level>, line 1:.+= combined { jq: 1 compile errorHere is the expected full JSON:
# echo "$full"{"hello": {"foo": {"version": "1.1.1" } },"world": {"bar": {"version": "2.2.2" } }"combined": {"foo": {"version": "1.1.1" },"bar": {"version": "2.2.2" } }}How to generate the "full" JSON with jq?