Скопируйте элемент верхнего уровня в каждый элемент массива, используя Jolt - PullRequest
0 голосов
/ 27 апреля 2020

Я работаю над пу sh вниз по полю верхнего уровня в каждом элементе массива внутри него.

Я хочу добавить sh sourceEntity в каждый элемент массива 'SupportCountries' и массива 'SupportCurrencies'

input JSON:

{
  "description": "SUPPORTED_COUNTRY_CURRENCY",
  "id": "20190902025202944",
  "type": "devuae-SUPPORTED_COUNTRY_CURRENCY",
  "sourceEntity": "EBI",
  "sourceChannel": "COR",
  "timestamp": "1567421549887",
  "supportedCountries": [
    {
      "code": "IN",
      "name": "India",
      "supportedCurrencies": [
        {
          "code": "JOD",
          "name": "JORDANIAN DINAR",
          "isLocal": true
        }
      ]
    }
  ]
}

Ожидаемый результат:

{
  "description": "SUPPORTED_COUNTRY_CURRENCY",
  "id": "20190902025202944",
  "type": "devuae-SUPPORTED_COUNTRY_CURRENCY",
  "sourceEntity": "EBI",
  "sourceChannel": "COR",
  "timestamp": "1567421549887",
  "supportedCountries": [
    {
      "EntityID": "EBI",
      "code": "IN",
      "name": "India",
      "supportedCurrencies": [
        {
          "UnitID": "EBI",
          "code": "JOD",
          "name": "JORDANIAN DINAR",
          "isLocal": true
        }
      ]
    }
  ]
}

Помогите мне решить эту проблему

1 Ответ

0 голосов
/ 28 апреля 2020

Может быть, это поможет,

[
  {
    "operation": "shift",
    "spec": {
      "description": "description",
      "id": "id",
      "type": "type",
      "sourceEntity": "sourceEntity",
      "sourceChannel": "sourceChannel",
      "timestamp": "timestamp",
      "supportedCountries": {
        "*": {
          //Shifting sourceEntity from the level 1
          "@(2,sourceEntity)": "supportedCountries[&1].EntityID",
          "code": "supportedCountries[&1].code",
          "name": "supportedCountries[&1].name",
          "supportedCurrencies": {
            "*": {
              //Shifting sourceEntity from the level 1
              "@(4,sourceEntity)": "supportedCountries[&1].supportedCurrencies[&1].UnitID",
              "code": "supportedCountries[&1].supportedCurrencies[&1].code",
              "name": "supportedCountries[&1].supportedCurrencies[&1].name",
              "isLocal": "supportedCountries[&1].supportedCurrencies[&1].isLocal"
            }
          }
        }
      }
    }
  }
]
...