JOLT - 转换为输出数组
JOLT - Transform into output array
我对 JOLT 有点陌生,一直在努力进行正确的转换。任何帮助表示赞赏。这是我的输入数据:
{
"data": {
"names": [
"columnA",
"columnB",
"columnC",
"columnD",
"columnE",
"columnF",
"columnG",
"columnH",
"columnI",
"columnJ",
"columnK"
],
"ndarray": [
[
0,
1,
2,
"aString",
"bString",
3,
4,
"Text in English (A)",
"Text in German (A)",
"Error id A",
"Error text A"
],
[
10,
11,
12,
"cString",
"dString",
13,
14,
"Text in English (B)",
"Text in German (B)",
"Error id B",
"Error text B"
]
]
}
}
我的目标是创建一个包含所有条目的数组。对于此示例,将有 2 个条目(长度与 data.ndarray
相同)。数组 data.ndnames
(键)和 data.ndarray[i]
(值)被映射 1:1,即它们应该具有相同的长度。
这是预期的输出:
{
"result": [
{
"columnA": 0,
"columnG": 4,
"columnC": 2,
"columnF": 3,
"explanation": [
{
"text": "Text in English (A)",
"lang": "EN" // constant value
},
{
"text": "Text in German (A)",
"lang": "DE" // constant value
}
],
"columnD": "aString",
"columnI": "Error id A",
"columnJ": "Error text A"
},
{
"columnA": 10,
"columnG": 14,
"columnC": 12,
"columnF": 13,
"explanation": [
{
"text": "Text in English (B)",
"lang": "EN" // constant value
},
{
"text": "Text in German (B)",
"lang": "DE" // constant value
}
],
"columnD": "cString",
"columnI": "Error id B",
"columnJ": "Error text B"
}
]
}
[编辑] 试试这个规范:
[
{
"operation": "shift",
"spec": {
"data": {
"ndarray": {
"*": {
"*": {
"@": "result[&2].@(4,names[&1])"
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"result": {
"*": {
"columnH": "result[&1].explanation[0].text",
"#EN": "result[&1].explanation[0].lang",
"columnI": "result[&1].explanation[1].text",
"#DE": "result[&1].explanation[1].lang",
"columnB": null,
"columnE": null,
"columnJ": "result[&1].columnI",
"columnK": "result[&1].columnJ",
"*": "result[&1].&"
}
}
}
}
]
我对 JOLT 有点陌生,一直在努力进行正确的转换。任何帮助表示赞赏。这是我的输入数据:
{
"data": {
"names": [
"columnA",
"columnB",
"columnC",
"columnD",
"columnE",
"columnF",
"columnG",
"columnH",
"columnI",
"columnJ",
"columnK"
],
"ndarray": [
[
0,
1,
2,
"aString",
"bString",
3,
4,
"Text in English (A)",
"Text in German (A)",
"Error id A",
"Error text A"
],
[
10,
11,
12,
"cString",
"dString",
13,
14,
"Text in English (B)",
"Text in German (B)",
"Error id B",
"Error text B"
]
]
}
}
我的目标是创建一个包含所有条目的数组。对于此示例,将有 2 个条目(长度与 data.ndarray
相同)。数组 data.ndnames
(键)和 data.ndarray[i]
(值)被映射 1:1,即它们应该具有相同的长度。
这是预期的输出:
{
"result": [
{
"columnA": 0,
"columnG": 4,
"columnC": 2,
"columnF": 3,
"explanation": [
{
"text": "Text in English (A)",
"lang": "EN" // constant value
},
{
"text": "Text in German (A)",
"lang": "DE" // constant value
}
],
"columnD": "aString",
"columnI": "Error id A",
"columnJ": "Error text A"
},
{
"columnA": 10,
"columnG": 14,
"columnC": 12,
"columnF": 13,
"explanation": [
{
"text": "Text in English (B)",
"lang": "EN" // constant value
},
{
"text": "Text in German (B)",
"lang": "DE" // constant value
}
],
"columnD": "cString",
"columnI": "Error id B",
"columnJ": "Error text B"
}
]
}
[编辑] 试试这个规范:
[
{
"operation": "shift",
"spec": {
"data": {
"ndarray": {
"*": {
"*": {
"@": "result[&2].@(4,names[&1])"
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"result": {
"*": {
"columnH": "result[&1].explanation[0].text",
"#EN": "result[&1].explanation[0].lang",
"columnI": "result[&1].explanation[1].text",
"#DE": "result[&1].explanation[1].lang",
"columnB": null,
"columnE": null,
"columnJ": "result[&1].columnI",
"columnK": "result[&1].columnJ",
"*": "result[&1].&"
}
}
}
}
]