Jolt:如何从对象列表中提取重复元素并在根级别添加一次
Jolt : How to extract repeatative element from list of objects and add once at the root level
我的输入样本 JSON,它在每个对象数组中有重复的 "total" 和 "nextpage" 元素,并且所有元素都具有相同的值。我需要在 "types" 键下方的顶层显示 "total" 和 "nextpage" 元素,并从其余 "total" 和 "nextpage" 元素中删除 JSON 文件.
{
"types": {
"coupontype1": [
{
"code": "XXX",
"exp_dt": "2020-01-01",
"total": 3,
"nextPage": "urllink"
},
{
"code": "YYY",
"exp_dt": "2019-12-01",
"total": 3,
"nextPage": "urllink"
}
],
"coupontype2": [
{
"code": "ZZZ",
"exp_dt": "2020-01-01",
"total": 3,
"nextPage": "urllink"
}
]
}
}
预期输出JSON
{
"types": {
"total": 3,
"nextPage": "urllink"
"coupontype1": [
{
"code": "XXX",
"exp_dt": "2020-01-01"
},
{
"code": "YYY",
"exp_dt": "2019-12-01"
}
],
"coupontype2": [
{
"code": "ZZZ",
"exp_dt": "2020-01-01"
}
]
}
}
我从上游组件收到了一个复杂的 JSON 结构,并使用 JOLT 模式将其结构化为我的输入 JSON,请帮助我为上述要求起草 JOLT 模式。我找不到解释 JOLT 模式设计的文档。在 JOLT 演示中尝试反复试验并参考示例以实现相同目的。但我完全陷入了这种情况。
查看内嵌评论以获取解释:
[
{
"operation": "shift",
"spec": {
"types": {
// get but don't match so next copy works.
// Using value of coupontype1.0.total|nextPage and set to types
"@(coupontype1)": {
"0": {
"total": "types.&",
"nextPage": "types.&"
}
},
// copy everything
"*": {
"@": "types.&1"
}
}
}
},
{
//remove total and nextPage
"operation": "remove",
"spec": {
"types": {
"*": {
"*": {
"total": "",
"nextPage": ""
}
}
}
}
}
]
我的输入样本 JSON,它在每个对象数组中有重复的 "total" 和 "nextpage" 元素,并且所有元素都具有相同的值。我需要在 "types" 键下方的顶层显示 "total" 和 "nextpage" 元素,并从其余 "total" 和 "nextpage" 元素中删除 JSON 文件.
{
"types": {
"coupontype1": [
{
"code": "XXX",
"exp_dt": "2020-01-01",
"total": 3,
"nextPage": "urllink"
},
{
"code": "YYY",
"exp_dt": "2019-12-01",
"total": 3,
"nextPage": "urllink"
}
],
"coupontype2": [
{
"code": "ZZZ",
"exp_dt": "2020-01-01",
"total": 3,
"nextPage": "urllink"
}
]
}
}
预期输出JSON
{
"types": {
"total": 3,
"nextPage": "urllink"
"coupontype1": [
{
"code": "XXX",
"exp_dt": "2020-01-01"
},
{
"code": "YYY",
"exp_dt": "2019-12-01"
}
],
"coupontype2": [
{
"code": "ZZZ",
"exp_dt": "2020-01-01"
}
]
}
}
我从上游组件收到了一个复杂的 JSON 结构,并使用 JOLT 模式将其结构化为我的输入 JSON,请帮助我为上述要求起草 JOLT 模式。我找不到解释 JOLT 模式设计的文档。在 JOLT 演示中尝试反复试验并参考示例以实现相同目的。但我完全陷入了这种情况。
查看内嵌评论以获取解释:
[
{
"operation": "shift",
"spec": {
"types": {
// get but don't match so next copy works.
// Using value of coupontype1.0.total|nextPage and set to types
"@(coupontype1)": {
"0": {
"total": "types.&",
"nextPage": "types.&"
}
},
// copy everything
"*": {
"@": "types.&1"
}
}
}
},
{
//remove total and nextPage
"operation": "remove",
"spec": {
"types": {
"*": {
"*": {
"total": "",
"nextPage": ""
}
}
}
}
}
]