JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
CSS
body {
font-family: monospace;
white-space: pre-wrap;
}
JavaScript
// uses lodash `mapValues` and `groupBy`
var nest = function (seq, keys) {
if (!keys.length)
return seq;
var first = keys[0];
var rest = keys.slice(1);
return _.mapValues(_.groupBy(seq, first), function (value) {
return nest(value, rest)
});
};
// nest data by `size` and then `category`
var nested = nest(getData(), ['size', 'category']);
document.write(JSON.stringify(nested, null, 4));
function getData() {
return [{
"size": 20,
"id": 1,
"externalid": 12266,
"pricedisplay": "$319,000 - $339,000",
"price": 319000,
"streetnumber": "40",
"streetname": "Lynlee Crescent",
"suburb": "HUNTFIELD HEIGHTS",
"region": "Southern Adelaide",
"postcode": 5163,
"state": "SA",
"geolocation": "-35.15102,138.509842",
"descriptionheadline": "A Great Start to Grow or Somewhere to Downsize!",
"descriptiondetail": "Situated in a very convenient close to local shops, transport and major shopping, schools and hospital are only a short distance away. Comprising 3 large bedrooms, master with built-in robes and central updated bathroom. Formal lounge, dining room, modern kitchen with stainless steel appliances plus walk-in pantry and large family room with built-in bar. Ducted evaporative cooling, gas heating plus combustion heater makes this home comfortable all year round. Step outside to the huge, all weather, peaked pergola area overlooking the low maintenance large yard with powered shed & toolshed. Drive through carport with roller door and relaxing sea views complete this fantastic offering. Call Belynda Horne 0417 876 663 to arrange an inspection, it won't last too long!",
"category": "Unit",
"saletype": "Sale",
"bedrooms": "3",
"bathrooms": 1,
"carspaces": 1,
"features": "",
"new": 0,
"premium": 1,
"inspections": "07\\/01\\/2012 14:00 14:30|||08\\/01\\/2012...