JSON rearrangement
<p>I have following object which I want to rearrange so I can pass to a template. Need help for converting it from following format</p>

<pre><code>var nature = [
  {
    "type": "fruit",
    "name": "apple",
    "color": "red",
  },
  {
    "type": "vegetable",
    "name": "carrot",
    "color": "orange",
  },
  {
    "type": "fruit",
    "name": "grape",
    "color": "green",
  },
  {
    "type": "vegetable",
    "name": "tamato",
    "color": "red",
  },
];
</code></pre>

<p>to this format</p>

<pre><code>var nature = [{
    "fruit": [
        {
            "type": "fruit",
            "name": "apple",
            "color": "red"
        },
        {
            "type": "fruit",
            "name": "grape",
            "color": "green"
        }
    ],
    "vegetable": [
        {
            "type": "vegetable",
            "name": "carrot",
            "color": "orange"
        },
        {
            "type": "vegetable",
            "name": "tomato",
            "color": "red"
        }
    ]
}];
</code></pre>

<p>Looking for quickest way of achieving it. Thanks for looking at the post. Appreciate the help. </p>
