在 JOLT 中比较和映射两个 objects 数组之间的值
Compare and map values between two array of objects in JOLT
我需要根据 dataKey 值映射 headers 和行值。
输入JSON
{
"headers": [
{
"dataKey": "col-0",
"displayName": "Product"
},
{
"dataKey": "col-1",
"displayName": "Dimension"
},
{
"dataKey": "col-2",
"displayName": "Output type "
}
],
"rows": [{
"col-0": "Medium ",
"col-1": "300x250",
"col-2": "HTML [Animate]"
}]
}
预期输出
{
"Data" : {
"1" : {
"Product":"Medium",
"Dimension":"300x250",
"Output type":"HTML [Animate]"
}
}
}
规格:
这是我目前使用的 JOLT 规范,它没有产生预期的输出
[
{
"operation": "shift",
"spec": {
"headers": {
"*": {
"displayName": {
"*": {
"@(2,dataKey)": {
"$": "Data.1.&",
"*": {
"@(6,rows.&)": "Data.1.&"
}
}
}
}
}
}
}
}
]
请提供上述 scanario 的颠簸规格。我试过了,但没能得到预期的结果。
[
{
// segregate values of the same key and form respective arrays.
"operation": "shift",
"spec": {
"headers": {
"*": {
"displayName": "@(1,dataKey)"
}
},
"rows": {
"*": {
"*": "&"
}
}
}
},
{
// put every value array into temp array
"operation": "shift",
"spec": {
"*": "temp[]"
}
},
{
// map first index element as key and second index element as a value into the output
"operation": "shift",
"spec": {
"temp": {
"*": {
"1": "Data.1.@(1,[0])"
}
}
}
}
]
我需要根据 dataKey 值映射 headers 和行值。
输入JSON
{
"headers": [
{
"dataKey": "col-0",
"displayName": "Product"
},
{
"dataKey": "col-1",
"displayName": "Dimension"
},
{
"dataKey": "col-2",
"displayName": "Output type "
}
],
"rows": [{
"col-0": "Medium ",
"col-1": "300x250",
"col-2": "HTML [Animate]"
}]
}
预期输出
{
"Data" : {
"1" : {
"Product":"Medium",
"Dimension":"300x250",
"Output type":"HTML [Animate]"
}
}
}
规格:
这是我目前使用的 JOLT 规范,它没有产生预期的输出
[
{
"operation": "shift",
"spec": {
"headers": {
"*": {
"displayName": {
"*": {
"@(2,dataKey)": {
"$": "Data.1.&",
"*": {
"@(6,rows.&)": "Data.1.&"
}
}
}
}
}
}
}
}
]
请提供上述 scanario 的颠簸规格。我试过了,但没能得到预期的结果。
[
{
// segregate values of the same key and form respective arrays.
"operation": "shift",
"spec": {
"headers": {
"*": {
"displayName": "@(1,dataKey)"
}
},
"rows": {
"*": {
"*": "&"
}
}
}
},
{
// put every value array into temp array
"operation": "shift",
"spec": {
"*": "temp[]"
}
},
{
// map first index element as key and second index element as a value into the output
"operation": "shift",
"spec": {
"temp": {
"*": {
"1": "Data.1.@(1,[0])"
}
}
}
}
]