THe trick for replacing a variable inside a json in bash is the following: close the single quotes (‘), put your variable in double quotes(“), add two single quotes (”)
Example: I want to replace ${LOWER_DATE_MILLI} inside an ElasticSearch query. My problem is that, some field are named like numbers! And I am forced to use single quotes, which does not allow me to replace variables. The trick is closing the single quotes, put my variable, and the re open the single quotes.
echo $MY_QUERY | jq ‘.aggs.”3″.aggs.”2″.date_histogram.extended_bounds.min=’”${LOWER_DATE_MILLI}””)