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

How to append records to a json object file in bash

$
0
0

I need to loop through a dictionary and append records to a json object file option.jsonthe code I have is

for K in "${!MYMAP[@]}"; do     opt="{        \"OptionName\":\"${K}\",        \"Value\":\"${MYMAP[$K]}\"        },"    echo $opt >> option.jsondone 

But this produce option.json as below

{"OptionName": "name","Value": "test"},{"OptionName": "age","Value": "13"}

How do i make the option.json a json object and appending each {} inside the object, so my option.json would look like below

[    {"OptionName": "name","Value": "test"    },    {"OptionName": "age","Value": "13"    }]

Viewing all articles
Browse latest Browse all 527

Trending Articles



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