title: Append data dynamically to existing JSON
body: <p>Given the following JSON structure,</p>
  
  <pre><code>#JSON 1
       {
              "objects": 
               [
                  {
                      "type": "chocolate",
                      "id": "c1"
                  },
                  {
                      "type": "sweet",
                      "id": "s1"
                  }
              ]
        }
  </code></pre>
  
  <p>How do I append data dynamically using Javascript? Something like this: </p>
  
  <pre><code>#JSON 2
           [
             {
              "data": {      
                      "type": "chocolate",
                      "id": "c1"
                  }
              },
              {
              "data": {
                      "type": "sweet",
                      "id": "s1"
                  }
              }
          ]
  </code></pre>
  
  <p>I've used the fetch API to read the file as it is a huge JSON file.
  and I do not want to hardcode type and id. What would be a better way to do this?</p>