Json 使用Jolt将3个嵌套列表中的数据展平到单个列表中

Json 使用Jolt将3个嵌套列表中的数据展平到单个列表中,json,jolt,Json,Jolt,实际需求是获取;每个json对象中的父id,如所需输出中所述。输入包含层次结构中的子级数组。相应的父id,即,如果id=A_B,则其父id应为A。 颠簸规范: [{ "operation": "shift", "spec": { "children": { "*": { "id2": "&", "name": "&",

实际需求是获取;每个json对象中的父id,如所需输出中所述。输入包含层次结构中的子级数组。相应的父id,即,如果id=A_B,则其父id应为A。 颠簸规范:

[{
        "operation": "shift",
        "spec": {
          "children": {
            "*": {

              "id2": "&",
              "name": "&",
              "path": "&",
              "@": "[&1]",
              "@(2,id)": "[&1].parent_id",
              "children": {
                "*": {
                  "@": "[&1]",
                  "@(3,id2)": "[&1].parent_id2"
                }
              }
            }
          }
        }
      }]
# 输入

{
  "categories": [
    {
      "id": "A",
      "name": "firstName",
      "path": "firstPath",
      "children": [
        {
          "id": "A_B",
          "name": "secondName",
          "path": "secondPath",
          "children": [
            {
              "id": "A_B_C",
              "name": "thirdName",
              "path": "thirdPath"
            }
          ]
        }
      ]
    }
  ]
}
# # 需要此输出

[{
  "id": "A",
  "name": "firstName",
  "path": "firstPath",
  "parentId": "0"
},
{
  "id": "A_B",
  "name": "secondName",
  "path": "secondPath",
  "parentId": "A"
},
{
  "id": "A_B_C",
  "name": "thirdName",
  "path": "thirdPath",
  "parentId": "A_B"
}]
#
规格:单独运行每个步骤,查看它在做什么

[
  {
    // bootstrap the root level to have "parentId": "0"
    "operation": "default",
    "spec": {
      "categories[]": {
        "0": {
          "parentId": "0"
        }
      }
    }
  },
  {
    // Build the "data" object you want, but you have to do it 
    //  maintaining the 3 levels of nested lists as the input
    //  so that the lookups will work.
    "operation": "shift",
    "spec": {
      "categories": {
        "*": {
          "*": "root[&1].data.&",
          "children": {
            "*": {
              "*": "root[&3].firstLevel[&1].data.&",
              "@(2,id)": "root[&3].firstLevel[&1].data.parent_id",
              "children": {
                "*": {
                  "*": "root[&5].firstLevel[&3].secondLevel[&1].data.&",
                  "@(2,id)": "root[&5].firstLevel[&3].secondLevel[&1].data.parent_id"
                }
              }
            }
          }
        }
      }
    }
  },
  {
    // Lastly, accumulate all the finished "data" elements from the 
    //  3 nested arrays  into a single top level array.
    "operation": "shift",
    "spec": {
      "root": {
        "*": {
          "data": "[]",
          "firstLevel": {
            "*": {
              "data": "[]",
              "secondLevel": {
                "*": {
                  "data": "[]"
                }
              }
            }
          }
        }
      }
    }
  }]

非常感谢米洛