[英]JSON Transformation using JOLT: Nested Array and Concatenation
我有以下輸入 JSON
[
{
"name": "Project1",
"Addresses": [
[
"B24",
"Niyam Street",
"67897",
"New York"
],
[
"A14",
"Prinston Str",
"London"
]
]
},
{
"name": "Project2",
"Addresses": [
[
"123",
"Portland Street",
"234"
],
[
"Lalbag",
"Kolaba"
],
[
"8th Avenue",
"3rd Signal"
]
]
}
]
我想將其轉換為如下所示:
[
{
"name": "Project1",
"Addresses": [
"B24 Niyam Street 67897 New York",
"A14 Prinston Str London"
]
},
{
"name": "Project2",
"Addresses": [
"123 Portland Street 234",
"Lalbag Kolaba",
"8th Avenue 3rd Signal"
]
}
]
Addresses 屬性值是一個動態大小的二維數組。
你能幫我提供一個有效的顛簸規范或一些提示來實現它嗎? 我搞不清楚了。 太感謝了。
您可以結合使用移位和修改轉換,例如
[
{
"operation": "shift",
"spec": {
"*": {
"*": "&", // the attributes other than "Addresses"
"Addresses": {
"*": "&1.&2.&" // determine the objects with indexed key names(0,1,2...) where &2 represents going two level up the tree to get the outermost indices of the objects of the main array, & for indices of the "Addresses" array, and &1 to keep the key name "Addresses" to transfer to the upcoming specs
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": {
"*": "=join(' ',@(1,&))" // concatenate all components of each array respectively at once
}
}
}
},
{
// combine the attributes back again
"operation": "shift",
"spec": {
"*": {
"*": "[&].&1"
},
"A*": {
"*": {
"*": "[&1].&2"
}
}
}
}
]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.