json - replace using bash - Dynamic value -


i have json file has following values

cat file     {     "key1": "value1"     "key2": "value2",     } 

i change value1 , value2. values dynamic changes overtime. sed should work value , mylook should key. " sed command not helping.

 sed -i 's/*\"key2\":*/\"key2\": "someothervalue2"/' file 

you should using proper json-parser instead of sed, e.g. jq.

infile

{   "key1" : "value1",   "key2" : "value2" } 

you can replace values this:

jq '.key1 = "foo" | .key2 = "bar"' < infile 

output:

{   "key1": "foo",   "key2": "bar" } 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -