JOLT:从另一个数组复制属性,按键值匹配
JOLT: copy attributes from another array, matching by key value
给出以下 input
json:
{
"colleges": [
{
"id": 10369272,
"name": "UNIVERSITY OF SAN DIEGO"
},
{
"id": 10331208,
"name": "UNIVERSITY OF CALIFORNIA - BERKELEY (EXTENSION)"
},
{
"id": 10331207,
"name": "SEATTLE PACIFIC UNIVERSITY"
}
],
"degrees": [
{
"id": 6215911,
"type": "Bachelor of Arts",
"collegeId": 10331207
},
{
"id": 6235281,
"type": "Bachelor of Science",
"collegeId": 10331208
}
]
}
和所需的 output
的:
{
"colleges": [
{
"name": "UNIVERSITY OF SAN DIEGO"
},
{
"name": "UNIVERSITY OF CALIFORNIA - BERKELEY (EXTENSION)",
"degreeType": "Bachelor of Science"
},
{
"name": "SEATTLE PACIFIC UNIVERSITY",
"degreeType": "Bachelor of Arts"
}
]
}
JOLT 规范如何将正确的学位与正确的大学相关联?
换句话说,我需要通过学院 ID 找到正确的 degree
,提取它的 type
并将其放在正确的 college
.
下
努力在某个地方找到类似的例子。
非常感谢任何建议。
您可以遍历 colleges 数组的索引以及 shift 转换
来自 &2[#(1)].@(1,id)
标识符的贡献
为了合并 common
下的属性
collegeId
( @(1,id)
和 @(3,degrees[&].collegeId)
) 包装所有对象集时的值
和colleges
数组(@(1,&2[#(1)])
)如
[
{
"operation": "shift",
"spec": {
"colleges": {
"*": {
"name": "&2[#1].@(1,id).&",
"@(2,degrees[&].type)": "&2[#].@(3,degrees[&].collegeId).degreeType"
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": {
"*": "&2"
}
}
}
}
]
给出以下 input
json:
{
"colleges": [
{
"id": 10369272,
"name": "UNIVERSITY OF SAN DIEGO"
},
{
"id": 10331208,
"name": "UNIVERSITY OF CALIFORNIA - BERKELEY (EXTENSION)"
},
{
"id": 10331207,
"name": "SEATTLE PACIFIC UNIVERSITY"
}
],
"degrees": [
{
"id": 6215911,
"type": "Bachelor of Arts",
"collegeId": 10331207
},
{
"id": 6235281,
"type": "Bachelor of Science",
"collegeId": 10331208
}
]
}
和所需的 output
的:
{
"colleges": [
{
"name": "UNIVERSITY OF SAN DIEGO"
},
{
"name": "UNIVERSITY OF CALIFORNIA - BERKELEY (EXTENSION)",
"degreeType": "Bachelor of Science"
},
{
"name": "SEATTLE PACIFIC UNIVERSITY",
"degreeType": "Bachelor of Arts"
}
]
}
JOLT 规范如何将正确的学位与正确的大学相关联?
换句话说,我需要通过学院 ID 找到正确的 degree
,提取它的 type
并将其放在正确的 college
.
努力在某个地方找到类似的例子。 非常感谢任何建议。
您可以遍历 colleges 数组的索引以及 shift 转换
来自 &2[#(1)].@(1,id)
标识符的贡献
为了合并 common
collegeId
( @(1,id)
和 @(3,degrees[&].collegeId)
) 包装所有对象集时的值
和colleges
数组(@(1,&2[#(1)])
)如
[
{
"operation": "shift",
"spec": {
"colleges": {
"*": {
"name": "&2[#1].@(1,id).&",
"@(2,degrees[&].type)": "&2[#].@(3,degrees[&].collegeId).degreeType"
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": {
"*": "&2"
}
}
}
}
]