Json 两个“之间的内部连接”;表格「;使用震动
我正在尝试使用两个对象数组和“join”将json转换为json文件,这是输入文件:Json 两个“之间的内部连接”;表格「;使用震动,json,merge,transform,transpose,jolt,Json,Merge,Transform,Transpose,Jolt,我正在尝试使用两个对象数组和“join”将json转换为json文件,这是输入文件: { "Employee": [ { "id": "emp_1", "firstName": "Jose", "lastName": "Perez", &q
{
"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": ""
}
}
}
}
]
首先,非常感谢您的回答,我正在查看您的答案,我喜欢它,我发现了一个稍微简单的方法,在链规范中只有两个大便(我将在其他答案中发布,请让我知道您的想法),关键是:“@(&)”我不知道如何做,再次非常感谢