使用JOLT在两个“表”之间进行内部联接

问题描述

我正在尝试使用两个对象数组和“ join”将json转换为json文件,这是输入文件

{
    "Employee": [
        {
            "id": "emp_1","firstName": "Jose","lastName": "Perez","ssn": "ssn1","depId": "dep_1"
        },{
            "id": "emp_2","firstName": "Antonio","lastName": "Ramirez","ssn": "ssn2","depId": "dep_2"
        }
    ],"Department": [
        {
            "id": "dep_1","description": "Instituto nacional de investigaciones nucleares (ININ)","division": "Research"
        },{
            "id": "dep_2","description": "Instituto Mexicano de Seguro Social (imsS)","division": "Healthcare"
        },{
            "id": "dep_3","description": "Comision Nacional Bancaria y de Valores (CNBV)","division": "Financial"
        }
    ]
}

这是预期的输出

{
    "Employee": [
        {
            "id": "emp_1","lasttName": "Perez","department": "Instituto nacional de investigaciones nucleares (ININ)","lasttName": "Ramirez","department": "Instituto Mexicano de Seguro Social (imsS)","division": "Healthcare"
        }
    ]
}

我一直在尝试做,但是没有被映射,我在做什么错? 这是我的规格:

[
    {
        "operation": "shift","spec": {
            "Department": {
                "*": {
                    "@" : "Department.@id"
                }
            },"Employee" : "Employee"
        }

    },{
        "operation": "shift","spec": {
            "Employee": {
                "*": {
                    "depId" : {
                        "*" : {
                            "@2" : {
                                "Department" : {
                                    "&4" : "test"
                                }    
                            }
                        }
                    }
                }
            }
        }

    }
]

请我已经花了很多时间来尝试解决它,有没有人知道如何使用Jolt来解决它:https://github.com/bazaarvoice/jolt

解决方法

检查此规范,使部门中的ID更易于访问,然后比较值,

[
  {
    "operation": "shift","spec": {
      "Employee": "Employee",//make the dep id easier to compare
      "Department": {
        "*": {
          "@": "Department.@(0,id)"
        }
      }
    }
  },{
    "operation": "shift","spec": {
      "Employee": {
        "*": {
          "depId": {
            "*": {
              "@(4,Department)": {
                // Compare values and move everything into the employee object
                "@3": "Employee.&","@(&)": "Employee.&.department"
              }
            }
          }
        }
      }
    }
  },"spec": {
      "Employee": {
        "*": {
          "@": "Employee[]"
        }
      }
    }
  },{
    // Object cleansing
    "operation": "shift","spec": {
      "Employee": {
        "*": {
          "id": "Employee[].id","firstName": "Employee[&1].firstName","lastName": "Employee[&1].lastName","ssn": "Employee[&1].ssn","department": {
            "description": "Employee[&2].department","division": "Employee[&2].division"
          }
        }
      }
    }
  }
]
,

非常感谢您的答复@Jagadesh 我或多或少地遵循了您的相同方法,但做了一些小的修改:

[
  {
    "operation": "shift","Department": {
        "*": {
          "@": "Department.@id"
        }
      }
    }
  },Department)": {
                "@(&)": {
                  "@(0,description)": "Employee[&5].department","@(0,division)": "Employee[&5].division"
                }
              }
            }
          },"@": "Employee[&]"
        }
      }
    }
  },// just to remove depId from Employee
  {
    "operation": "remove","spec": {
      "Employee": {
        "*": {
          "depId": ""
        }
      }
    }
  }
]