Source https://stackoverflow.com/questions/25378013/how-to-convert-a-json-object-to-key-value-format-in-jq
Given:
{
"demo_name": "Jane Doe",
"demo_id": "339e42a6-045a-47b5-98a4-310dd53d1053",
"demo_phone": "555-123-4567"
}
Shell function json2env
json2env() {
for v in $(jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' $1)
do
export $v
done
}
Source function and run ...
-> json2env doe.json
-> env|grep demo
demo_name=Jane
demo_phone=555-123-4567
demo_id=339e42a6-045a-47b5-98a4-310dd53d1053