Has anyone got any tips on processing data to give it the hierarchical child parent relationships that D3 uses with d3.hierarchy? I wonder if there are tools to assist with the processing and validation for relationships of the data. All tips, questions and comments welcome.
no3_hierarchy = {
 if(nitrateData[nitrateData.length-1].children!='root') {  // add a root parent node
   nitrateData.push({parent: "",
                     geography_type: "New Zealand",
                     geography_name: "Aotearoa" ,
                     children: "root",
                     animal: "",          // not sure if I need these but have them incase structure is needed
                     year: "1990",
                     no3_kg_per_yr: 0
                    })
 } 
 let no3h = nitrateData.filter( d => {
    d.year=''+d.year                              // fix the auto format make the year a string
    if (d.no3_kg_per_yr==-1) d.no3_kg_per_yr =0   // fix up the NA -1 data to read zero as some regions used 0 and others NA
    
    switch(d.geography_name){  // add child parent relationships.
        case 'New Zealand':
          d.children=d.geography_name+d.animal+d.year
          d['parent']='root'
          break;
        case 'North Island':
        case 'South Island':
          d.children=d.geography_name+d.animal+d.year
          d['parent']='New Zealand'+d.animal+d.year
          break;
        case "Auckland":
        case "Bay of Plenty":
        case "Gisborne":
        case "Hawke's Bay":
        case "Manawatu-Whanganui":
        case "Waikato":
        case "Wellington":
        case "Northland":
        case "Taranaki":     
          d.children = d.geography_name+d.animal+d.year
          d.parent = 'North Island'+d.animal+d.year
          break;
        case "Otago":
        case "Southland":
        case "Marlborough":
        case "Tasman":
        case "West Coast":
        case "Canterbury":
          d.children = d.geography_name+d.animal+d.year
          d.parent = 'South Island'+d.animal+d.year
          break;
      }
   return d
  })
  return no3h
} Thanks for pointing me in the right direction.
   Thanks for pointing me in the right direction.

 udate: changed code to that and then added images )
  udate: changed code to that and then added images ) Sorry for the extra noise!
  Sorry for the extra noise!