Merge JSON file

The following is a simple piece of code to reduce the workload to merge code

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script>
let BIG = {};let SM = {};
let BIGObj = JSON.parse(JSON.stringify(BIG))
let SMObj = JSON.parse(JSON.stringify(SM))
for(var key in SMObj) {
  if(!BIGObj[key]){
    BIGObj[key] = SMObj[key]
  }
  if(SMObj[key] instanceof Object){
    for(var a in SMObj[key]){
      if(!BIGObj[key][a]){
        BIGObj[key][a] = SMObj[key][a]
      }
    }
  }
}

console.log(JSON.stringify(BIGObj))
  </script>
</body>
</html>

Guess you like

Origin www.cnblogs.com/sugartang/p/12101193.html