json 为比赛而震动变换

piv4azn7  于 2023-08-08  发布在  其他
关注(0)|答案(1)|浏览(91)

我想使用jolt转换来检查数据是否匹配。

输入

{
  "nodes": [
    {
      "id": "Type:APPLICATION_COMPONENT, id:206180",
      "flowMapNodeType": "MAIN_DASHBOARD_NODE",
      "name": "WebFrontEnd",
      "viewPermission": true,
      "agentUp": false
    },
    {
      "id": "Type:APPLICATION_COMPONENT, id:206183",
      "flowMapNodeType": "MAIN_DASHBOARD_NODE",
      "name": "AccountManagement",
      "viewPermission": true,
      "agentUp": false
    },
    {
      "id": "Type:APPLICATION_COMPONENT, id:206188",
      "flowMapNodeType": "MAIN_DASHBOARD_NODE",
      "name": "PerLoanServices",
      "viewPermission": true,
      "agentUp": false
    },
    {
      "id": "Type:APPLICATION_COMPONENT, id:206182",
      "flowMapNodeType": "MAIN_DASHBOARD_NODE",
      "name": "PolicyServices",
      "viewPermission": true,
      "agentUp": false
    },
    {
      "id": "Type:APPLICATION_COMPONENT, id:206184",
      "flowMapNodeType": "MAIN_DASHBOARD_NODE",
      "name": "BizLoanServices",
      "viewPermission": true,
      "agentUp": false
    },
    {
      "id": "Type:APPLICATION_COMPONENT, id:206185",
      "flowMapNodeType": "MAIN_DASHBOARD_NODE",
      "name": "BalanceServices",
      "viewPermission": true,
      "agentUp": false
    },
    {
      "id": "Type:APPLICATION_COMPONENT, id:206186",
      "flowMapNodeType": "MAIN_DASHBOARD_NODE",
      "name": "SessionTracking",
      "viewPermission": true,
      "agentUp": false
    }
  ],
  "sourceNode": "Type:APPLICATION_COMPONENT, id:206183",
  "targetNode": "Type:APPLICATION_COMPONENT, id:206184"
}

字符串
如果sourceNodenodes子阵列中的node.id匹配,则将添加新字段sourceNodeName,其是相同idnode.name字段。类似地,targetNode与节点子阵列中的node.id匹配,则将添加新字段targetNodeName,其是相同idnode.name字段。

此输入的预期输出

{
  "sourceNodeName" : "AccountManagement",
  "targetNodeName" : "BizLoanServices"
  "sourceNode" : "Type:APPLICATION_COMPONENT, id:206183",
  "targetNode" : "Type:APPLICATION_COMPONENT, id:206184"
}

kokeuurv

kokeuurv1#

您可以使用以下转换:

[
  { // add keys to the objects, which are under "nodes" array, with "id" values  
    "operation": "shift",
    "spec": {
      "nodes": {
        "*": {
          "*": "@1,id.&"
        }
      },
      "*": "&"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*Node": { // loop only within the "sourceNode" and "targetNode" attributes
        "*": {
          "@(2,&)": { "name": "&3&" } // &3 : Bring the key name after going 3 levels up
        },
        "@": "&" // key-value pair for the upper nodes, eg. "sourceNode" and "targetNode"
      }
    }
  }
]

字符串
网站http://jolt-demo.appspot.com/上的 * 演示 * 是:


的数据

相关问题