0
Follow
0
View

JSON transformation using JOLT for Multiple arrays

patvice 注册会员
2023-01-25 19:43

@ Barbaros Özhan, Thank you so much, below one is producing the required result..

[ { "operation": "shift",

"spec": {

  "d": {

    "results": {


      "*": {
        "VendorNu*": "vendors[&1].name",
        "VendorNa*": "vendors[&1].&",
        "Bank*": {
          "results": {
            "*": {
              "BankKey": "vendors[&4].Bank[&1].bsb",
              "BankAccount": "vendors[&4].Bank[&1].account_number"
            }
          }
        }
      }
    }
  }
}

} ]

tongwenbin1984 注册会员
2023-01-25 19:43

You can collect the elements "VendorNumber", "VendorName" and the object with key name "BankDetailSet" under common object notation, then set the relative positioning wildcards such as [&1], [&4] to meet at the same level of indexes of the outermost "results" array such as

[
  {
    "operation": "shift",
    "spec": {
      "d": {
        "results": {
          "*": {
            "VendorNu*": "vendors[&1].name",
            "VendorNa*": "vendors[&1].&",
            "Bank*": {
              "results": {
                "*": {
                  "Bank*": "vendors[&1].Bank[&4].&(0,1)"
                }
              }
            }
          }
        }
      }
    }
  }
]

the demo on the site http://jolt-demo.appspot.com/ is

Edit : What you need within the last comments is just reverse of the previous one, eg. use

"Bank*": "vendors[&4].Bank[&1].&(0,1)"

instead of

"Bank*": "vendors[&1].Bank[&4].&(0,1)" 

or literally use (as in your case)

"BankKey": "vendors[&4].Bank[&1].bsb",
"BankAccount": "vendors[&4].Bank[&1].account_number"

such as

[
  {
    "operation": "shift",
    "spec": {
      "d": {
        "results": {
          "*": {
            "VendorNu*": "vendors[&1].name",
            "VendorNa*": "vendors[&1].&",
            "Bank*": {
              "results": {
                "*": {
                  "BankKey": "vendors[&4].Bank[&1].bsb",
                  "BankAccount": "vendors[&4].Bank[&1].account_number"
                }
              }
            }
          }
        }
      }
    }
  }
]

the is

About the Author

Question Info

Publish Time
2023-01-25 19:43
Update Time
2023-01-25 19:43

Related Question