Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
const data = {
    "Name": {
        "S": "Jon Snow"
    },
    "Location": {
        "S": "Winterfell"
    },
    "Details": {
        "M": {
            "Parents": {
                "M": {
                    "mother": {
                        "S": "Lynna Stark"
                    }
                }
            },
            "Dog": {
                "N": "Ghost Snow"
            }
        }
    }
}
const flatten = (data) =>{
  if(typeof data === "string") return data;
  for(let key in data){
    for(let deep in data[key]){
      if(deep.length === 1){
        const temp = data[key]
        data[key] = flatten(temp[deep])
      }
    }
  }
  return data;
}
console.log( JSON.stringify(flatten(data), null, "\t"))
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers