-1

Unable to transform the below Input json into expected format using JOLT.

Note: FExchangeCurrency_ExchangeRate values need to get in 2nd row in Expected output.

Input:

[
  {
    "ExchangeCurrency": "INR",
    "FExchangeCurrency": "AUD",
    "ExchangeRate": 123,
    "ExchangeDate2": "2023-05-01"
  },
  {
    "ExchangeCurrency": "INR",
    "FExchangeCurrency": "CHF",
    "ExchangeRate": 234,
    "ExchangeDate2": "2023-05-01"
  },
  {
    "ExchangeCurrency": "INR",
    "FExchangeCurrency": "EUR",
    "ExchangeRate": 456,
    "ExchangeDate2": "2023-05-01"
  }
]

Expected Output:

{
  "ExchangeCurrency" : "INR",
  "ExchangeDate2" : "2023-05-01",
  "AUD_ExchangeRate" : 123,
  "CHF_ExchangeRate" : 234,
  "EUR_ExchangeRate" : 456
}
Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
pandu
  • 31
  • 4

1 Answers1

1

You can use the following spec

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "ExchangeRat*": "@(1,FExchangeCurrency)_&",
        "ExchangeD*|ExchangeC*": "X.&" // others, which has no rendering applied, qualified with an arbitrary letter X
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "&1&"
      },
      "X": {
        "*": {
          "0": "&1" // only pick single one of repeated identical components
        }
      }
    }
  }
]
Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55