How to change JSON structure in JavaScript : <p>I need to change JSON structure but I'm struggling how to do it, and also I'm not sure if I need to create a new object or I can just work on the current one?</p>

<p>Anyway this is the JSON I want to change:</p>

<pre><code>{
  "start": [
     {"time": 22, "value": 324, "year": 2016},
     {"time": 142, "value": 234, "year": 2016},
     ...
  ],
  "end": [
     {"time": 123, "value": 254, "year": 2016},
     ...
  ]
}
</code></pre>

<p>And change it to this:</p>

<pre><code>{
  "key": "start",
  "values": [
     {"time": 22, "value": 324, "year": 2016}, 
     {"time": 142, "value": 234, "year": 2016},
     ...
  ]
 }, {
  "key": "end",
  "values": [
     {"time": 123, "value": 254, "year": 2016},
     ...
  ]
}
</code></pre>
