Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 两个“之间的内部连接”;表格「;使用震动_Json_Merge_Transform_Transpose_Jolt - Fatal编程技术网

Json 两个“之间的内部连接”;表格「;使用震动

Json 两个“之间的内部连接”;表格「;使用震动,json,merge,transform,transpose,jolt,Json,Merge,Transform,Transpose,Jolt,我正在尝试使用两个对象数组和“join”将json转换为json文件,这是输入文件: { "Employee": [ { "id": "emp_1", "firstName": "Jose", "lastName": "Perez", &q

我正在尝试使用两个对象数组和“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",
            "firstName": "Jose",
            "lasttName": "Perez",
            "ssn": "ssn1",
            "department": "Instituto nacional de investigaciones nucleares (ININ)",
            "division": "Research"
        },
        {
            "id": "emp_2",
            "firstName": "Antonio",
            "lasttName": "Ramirez",
            "ssn": "ssn2",
            "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解决它:?

检查此规范,使部门中的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"
              }
            }
          }
        }
      }
    }
  }, {
    "operation": "shift",
    "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",
    "spec": {
      "Employee": "Employee",
      "Department": {
        "*": {
          "@": "Department.@id"
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "Employee": {
        "*": {
          "depId": {
            "*": {
              "@(4,Department)": {
                "@(&)": {
                  "@(0,description)": "Employee[&5].department",
                  "@(0,division)": "Employee[&5].division"
                }
              }
            }
          },
          "@": "Employee[&]"
        }
      }
    }
  },


  // just to remove depId from Employee
  {
    "operation": "remove",
    "spec": {
      "Employee": {
        "*": {
          "depId": ""
        }
      }
    }
  }
]

首先,非常感谢您的回答,我正在查看您的答案,我喜欢它,我发现了一个稍微简单的方法,在链规范中只有两个大便(我将在其他答案中发布,请让我知道您的想法),关键是:“@(&)”我不知道如何做,再次非常感谢