You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

多层嵌套JSON对象无数据丢失合并实现方案技术问询

多层级JSON对象合并需求

我需要合并两个多层级JSON对象,生成无数据丢失的单一对象。合并规则为:层级数据完全一致时不新增额外字段,同一层级字段存在差异时,将新对象插入对应数组中。
我们需要将字段相似的JSON对象分组整合为一个完整JSON,对多层级对象合并以得到聚合结果。

示例输入对象

let one = {
  "name": "Hindi",
  "country": "USA",
  "region": "EAST COAST",
  "enttity": "ENTITY-2",
  "operation": [
    {
      "p_name": "RECONSTRUCTION",
      "code": "jhhkj-132",
      "class": "medical",
      "products": [
        {
          "main": "electronic",
          "area": [
            {
              "subarea": "electrical",
              "use": 0,
              "max_use": 0,
              "mode_use": "10",
              "median": "12",
              "things": [
                {
                  "id": "1000514",
                  "number": "1588TB-1",
                  "description": "DESCRIPTION1",
                  "manufacturer": "LG",
                  "tag": "NOT AVAILABLE"
                }
              ]
            }
          ]
        }
      ]
    }
  ]
};

let two = {
  "name": "Hindi",
  "country": "USA",
  "region": "EAST COAST",
  "enttity": "ENTITY-2",
  "operation": [
    {
      "p_name": "RECONSTRUCTION",
      "code": "jhhkj-132",
      "class": "medical",
      "products": [
        {
          "main": "electronic",
          "area": [
            {
              "subarea": "mechanical",
              "use": 0,
              "max_use": 0,
              "mode_use": "10",
              "median": "12",
              "things": [
                {
                  "id": "1000523314",
                  "number": "1588T3B-1",
                  "description": "DES32CRIPTION1",
                  "manufacturer": "LG",
                  "tag": "NOT AVAILABLE"
                }
              ]
            },
            {
              "subarea": "electrical",
              "use": 0,
              "max_use": 0,
              "mode_use": "10",
              "median": "12",
              "things": [
                {
                  "id": "1000514",
                  "number": "1588TB-1",
                  "description": "DESCRIPTION1",
                  "manufacturer": "LG",
                  "tag": "NOT AVAILABLE"
                }
              ]
            }
          ]
        }
      ]
    }
  ]
};

期望输出结果

let output = {
  "name": "Hindi",
  "country": "USA",
  "region": "EAST COAST",
  "enttity": "ENTITY-2",
  "operation": [
    {
      "p_name": "RECONSTRUCTION",
      "code": "jhhkj-132",
      "class": "medical",
      "products": [
        {
          "main": "electronic",
          "area": [
            {
              "subarea": "mechanical",
              "use": 0,
              "max_use": 0,
              "mode_use": "10",
              "median": "12",
              "things": [
                {
                  "id": "1000523314",
                  "number": "1588T3B-1",
                  "description": "DES32CRIPTION1",
                  "manufacturer": "LG",
                  "tag": "NOT AVAILABLE"
                }
              ]
            },
            {
              "subarea": "electrical",
              "use": 0,
              "max_use": 0,
              "mode_use": "10",
              "median": "12",
              "things": [
                {
                  "id": "1000514",
                  "number": "1588TB-1",
                  "description": "DESCRIPTION1",
                  "manufacturer": "LG",
                  "tag": "NOT AVAILABLE"
                }
              ]
            }
          ]
        }
      ]
    }
  ]
};

内容的提问来源于stack exchange,提问作者shashank yadav

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 18:36:07