JSFiddle - React, Tailwind, and code Playground

by Chetan Hanumantha

JavaScript

var input = {
    "yellow": {
        "red": {
            "green" : "x"
        },
        "blue": "y"
      },
    "black": "y"
}


var output = {
    "yellow.red.green": "x",
    "black": "y",
    "yellow.blue": "y"
}


function getOutput(inputJson, resultKey) {
	 console.log(typeof inputJson !== 'object');
   console.log(inputJson);
   if(typeof inputJson !== 'object') {
   		return inputJson;
   }else {
   		var keys = Object.keys(inputJson);
      console.log(keys);
      for(var k=0; k<keys.length; k++) {
      	var val = getOutput(inputJson[keys[k]], ');
        console.log('Val'+val);
        var obj = {};
        obj[resultKey+'.'+keys[k]] = val;
        return obj;
      }
   }
}


var result = getOutput(input, null);
console.log(result);