title: Replace Content in place using sed in a JSON file
body: <p>My <code>JSON</code> file is as follows:</p>
  
  <pre><code>{
   "Name":"SA",
   "Password":"yyyyy",
   "Mappings" : {
   "RegionMap" : {
       "us-east-1"      : { "AMI" : "xxxxxx" },
       "us-east-2"      : { "AMI" : "" },
       "us-west-1"      : { "AMI" : "" },
       "us-west-2"      : { "AMI" : "" },
       "ca-central-1"   : { "AMI" : "" },
       "eu-central-1"   : { "AMI" : "" },
       "eu-west-1"      : { "AMI" : "" },
       "eu-west-2"      : { "AMI" : "" },
       "ap-south-1"     : { "AMI" : "" },
       "ap-southeast-1" : { "AMI" : "" },
       "ap-southeast-2" : { "AMI" : "" },
       "ap-northeast-1" : { "AMI" : "" },
       "ap-northeast-2" : { "AMI" : "" },
       "sa-east-1"      : { "AMI" : "" }       
      }
    }
  }
  </code></pre>
  
  <p>My <code>task</code> is to update the value of the <code>AMI</code> key of <code>us-east-1</code> in the given <code>json</code> file. I have used <a href="https://github.com/stedolan/jq" rel="nofollow noreferrer">jq</a> to solve this issue . Here is the <a href="https://stackoverflow.com/questions/45061585/update-contents-of-file-via-jq-using-redirection-operator">link</a>. I am having problems with <a href="https://github.com/stedolan/jq" rel="nofollow noreferrer">jq</a> no being stable on my <code>windows</code> server machine. So now I want to obtain the same using <code>sed</code> commands. </p>
  
  <p>My <code>expected output</code> is as follows</p>
  
  <pre><code>{
  "Name":"SA",
  "Password":"yyyyy",
  "Mappings" : {
  "RegionMap" : {
     "us-east-1"      : { "AMI" : "abcd" },
     "us-east-2"      : { "AMI" : "" },
     "us-west-1"      : { "AMI" : "" },
     "us-west-2"      : { "AMI" : "" },
     "ca-central-1"   : { "AMI" : "" },
     "eu-central-1"   : { "AMI" : "" },
     "eu-west-1"      : { "AMI" : "" },
     "eu-west-2"      : { "AMI" : "" },
     "ap-south-1"     : { "AMI" : "" },
     "ap-southeast-1" : { "AMI" : "" },
     "ap-southeast-2" : { "AMI" : "" },
     "ap-northeast-1" : { "AMI" : "" },
     "ap-northeast-2" : { "AMI" : "" },
     "sa-east-1"      : { "AMI" : "" }       
     }
   }
  }
  </code></pre>
  
  <p>I have referred many questions relating to this on <code>stackoverflow</code> relating to this issue but I am unable to get the desired output. The links of the questions referred are as follows</p>
  
  <ol>
  <li><p><a href="https://askubuntu.com/questions/20414/find-and-replace-text-within-a-file-using-commands">Find and replace text within a file using commands</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/26281538/find-and-replace-for-json-with-sed-or-awk">Find and replace for JSON with sed or awk</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/15272244/how-to-replace-value-of-key-in-json-file-using-sed">How to replace value of key in json file using sed</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/39239522/use-sed-to-find-and-replace-json-field">Use Sed to find and replace json field</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/35868649/replace-value-in-json-during-run-time">Replace value in json during run time</a></p></li>
  </ol>
  
  <p>Can somebody help me with this? Also is it possible that I can use environment variables value for replacing the contents of the file in place? If so, how?</p>
  
  <p>Edit </p>
  
  <p>I have already got the answer using jq. The link is mentioned above. Since jq is unstable on my windows server machine I am trying to achieve the same using sed commands.</p>