json_data内容如下:
{
"honesty": "haaaaa",
"laughter": "Pinkie Pie",
"loyalty": "Rainbow Dash"
}
修改脚本如下:
cat json_data |
jq 'to_entries |
map(if .key == "honesty"
then . + {"value":"hello world"}
else .
end
) |
from_entries' > json_data_temp
if [ -f "json_data_temp" ]; then
echo "file exist"
mv json_data_temp json_data
else
echo "file not exist or file size is 0"
fi