Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 657

How to add and combine objects in jq

$
0
0

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 error

Here 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?


Viewing all articles
Browse latest Browse all 657

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>