How can I remap one JSON lines to hierachycal JSON? How can I remap one JSON lines to hierachycal JSON? json json

How can I remap one JSON lines to hierachycal JSON?


Since you're going to be doing a bunch of lookups I suggest using a collection of objects rather than your final structure with arrays. You can then either convert it to the final structure or modify code to use it the way it is.

var countries = {};for (var i=0, loc; loc = locations[i]; i++) {    if (!countries[loc.country]) countries[loc.country] = {};    if (!countries[loc.country][loc.area]) countries[loc.country][loc.area] = [];    countries[loc.country][loc.area].push(loc.city);}alert(JSON.stringify(countries));