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

基于JOLT实现多场景嵌套JSON至扁平JSON的转换需求

JOLT 嵌套转扁平JSON解决方案

场景1:SalesArea为列表且无嵌套PartnerFunction

输入示例:

{
  "Order": "ORD001",
  "SalesArea": [
    {
      "SalesOrg": "S001",
      "DistChannel": "D01",
      "Division": "DV1"
    },
    {
      "SalesOrg": "S002",
      "DistChannel": "D02",
      "Division": "DV2"
    }
  ]
}

期望输出:

[
  {
    "Order": "ORD001",
    "SalesOrg": "S001",
    "DistChannel": "D01",
    "Division": "DV1"
  },
  {
    "Order": "ORD001",
    "SalesOrg": "S002",
    "DistChannel": "D02",
    "Division": "DV2"
  }
]

转换规则:

[
  {
    "operation": "shift",
    "spec": {
      "SalesArea": {
        "*": {
          "@(2,Order)": "[&1].Order",
          "*": "[&1].&"
        }
      }
    }
  }
]

场景2:SalesArea为单个对象且包含PartnerFunction列表

输入示例:

{
  "Order": "ORD002",
  "SalesArea": {
    "SalesOrg": "S003",
    "DistChannel": "D03",
    "Division": "DV3",
    "PartnerFunction": [
      {
        "Role": "SP",
        "Party": "P001"
      },
      {
        "Role": "SH",
        "Party": "P002"
      }
    ]
  }
}

期望输出:

[
  {
    "Order": "ORD002",
    "SalesOrg": "S003",
    "DistChannel": "D03",
    "Division": "DV3",
    "Role": "SP",
    "Party": "P001"
  },
  {
    "Order": "ORD002",
    "SalesOrg": "S003",
    "DistChannel": "D03",
    "Division": "DV3",
    "Role": "SH",
    "Party": "P002"
  }
]

转换规则:

[
  {
    "operation": "shift",
    "spec": {
      "SalesArea": {
        "PartnerFunction": {
          "*": {
            "@(3,Order)": "[&1].Order",
            "@(2,SalesOrg)": "[&1].SalesOrg",
            "@(2,DistChannel)": "[&1].DistChannel",
            "@(2,Division)": "[&1].Division",
            "*": "[&1].&"
          }
        }
      }
    }
  }
]

场景3:SalesArea为列表且每个元素包含PartnerFunction列表

输入示例:

{
  "Order": "ORD003",
  "SalesArea": [
    {
      "SalesOrg": "S004",
      "DistChannel": "D04",
      "Division": "DV4",
      "PartnerFunction": [
        {
          "Role": "SP",
          "Party": "P003"
        },
        {
          "Role": "BP",
          "Party": "P004"
        }
      ]
    },
    {
      "SalesOrg": "S005",
      "DistChannel": "D05",
      "Division": "DV5",
      "PartnerFunction": [
        {
          "Role": "SH",
          "Party": "P005"
        }
      ]
    }
  ]
}

期望输出:

[
  {
    "Order": "ORD003",
    "SalesOrg": "S004",
    "DistChannel": "D04",
    "Division": "DV4",
    "Role": "SP",
    "Party": "P003"
  },
  {
    "Order": "ORD003",
    "SalesOrg": "S004",
    "DistChannel": "D04",
    "Division": "DV4",
    "Role": "BP",
    "Party": "P004"
  },
  {
    "Order": "ORD003",
    "SalesOrg": "S005",
    "DistChannel": "D05",
    "Division": "DV5",
    "Role": "SH",
    "Party": "P005"
  }
]

转换规则:

[
  {
    "operation": "shift",
    "spec": {
      "SalesArea": {
        "*": {
          "PartnerFunction": {
            "*": {
              "@(4,Order)": "[&3].Order",
              "@(2,SalesOrg)": "[&3].SalesOrg",
              "@(2,DistChannel)": "[&3].DistChannel",
              "@(2,Division)": "[&3].Division",
              "*": "[&3].&"
            }
          }
        }
      }
    }
  },
  {
    "operation": "remove",
    "spec": {
      "*": {
        "PartnerFunction": ""
      }
    }
  }
]

内容的提问来源于stack exchange,提问作者Thiyagaraj Narayanan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 04:40:15