title: Update JSON value for a particular key, preserving JSON structure
body: <p>I need to update the value for key (<code>id</code>) in the JSON file. Value is stored in the variable <code>ids</code>. I am able to update the key <code>id</code> with <code>ids</code> (updated value), but the structure of the JSON file gets messed up. Can anyone suggest me a way to doing it without messing up the JSON structure?</p>
  
  <p>Code:</p>
  
  <pre><code>ids=10
  filename='update_test.json'
  with open(filename,'r') as f:
      data=json.load(f)
      data['id'] = ids
  os.remove(filename)
  with open(filename,'w') as f:
      json.dump(data,f,indent=4)
  </code></pre>
  
  <p>Input JSON:</p>
  
  <pre><code>{
      "accountableExecutiveTech": "string",
      "api": true,
      "arrivalFrequency": "string",
      "bucketName": "string",
      "businessDataset": "string",
      "columns": [{
          "businessColumnName": "string",
          "childColumns": [{}],
          "columnOrder": 0,
          "description": "string",
          "descriptiveName": "string",
          "format": "string",
          "hierarchicalName": "string",
          "id": 0,
          "isArray": true,
          "length": 0,
          "name": "string",
          "parentColumnName": "string",
          "partitionColumn": true,
          "technicalDatasetId": 0,
          "technicalDatasetName": "string",
          "technicalNamespace": "string",
          "technicalPlatformName": "string",
          "type": "string",
          "validValues": {}
      }],
      "controlMJobName": "string",
      "credit": true,
      "delimiter": "string",
      "delimiterFlag": true,
      "description": "string",
      "dqPrioritized": true,
      "fileFormat": "string",
      "id": "",
      "name": "string",
      "namespace": "string",
      "npi": true,
      "objectKey": "string",
      "pci": true,
      "performingDataSteward": "string",
      "platformName": "string",
      "retentionPlan": "string",
      "selectAdGroup": "string",
      "sourceDatasets": [{
          "id": 4534,
          "name": "string",
          "namespace": "string",
          "platformName": "string"
      }],
      "tags": ["string"]
  }
  </code></pre>
  
  <p>Output JSON:</p>
  
  <pre><code>{
      "accountableExecutiveTech": "string",
      "delimiterFlag": true,
      "performingDataSteward": "string",
      "api": true,
      "dqPrioritized": true,
      "id": 14044,
      "namespace": "string",
      "fileFormat": "string",
      "selectAdGroup": "string",
      "pci": true,
      "platformName": "string",
      "columns": [
          {
              "isArray": true,
              "partitionColumn": true,
              "description": "string",
              "technicalDatasetId": 0,
              "format": "string",
              "technicalPlatformName": "string",
              "parentColumnName": "string",
              "columnOrder": 0,
              "length": 0,
              "childColumns": [
                  {}
              ],
              "descriptiveName": "string",
              "validValues": {},
              "technicalDatasetName": "string",
              "technicalNamespace": "string",
              "hierarchicalName": "string",
              "businessColumnName": "string",
              "type": "string",
              "id": 0,
              "name": "string"
          }
      ],
      "businessDataset": "string",
      "npi": true,
      "description": "string",
      "tags": [
          "string"
      ],
      "arrivalFrequency": "string",
      "objectKey": "string",
      "bucketName": "string",
      "controlMJobName": "string",
      "name": "string",
      "retentionPlan": "string",
      "credit": true,
      "delimiter": "string",
      "sourceDatasets": [
          {
              "platformName": "string",
              "namespace": "string",
              "id": 4534,
              "name": "string"
          }
      ]
  </code></pre>