Борьба с JOLT concat - PullRequest
       9

Борьба с JOLT concat

0 голосов
/ 24 января 2020

Я борюсь с преобразованием, используя JOLT.

Ввод:

{
  "records": [
    {"counters": "Item1 Item2 Item3 Item4 Item5 Item6",
      "values": "V1 V2 V3 V4 V5 V6"},
    {"counters": "Item7 Item8 Item9 Item10 Item11",
      "values": "V7 V8 V9 V10 V11"},
    {"counters": "Item12 Item13",
      "values": "V12 V13"},
    {"counters": "Item14",
      "values": "V14"}
  ]
}

Желаемый вывод:

{
  "xItem1" : "V1",
  "xItem2" : "V2",
  "xItem3" : "V3",
  "xItem4" : "V4",
  "xItem5" : "V5",
  "xItem6" : "V6",
  "xItem7" : "V7",
  "xItem8" : "V8",
  "xItem9" : "V9",
  "xItem10" : "V10",
  "xItem11" : "V11",
  "xItem12" : "V12",
  "xItem13" : "V13",
  "xItem14" : "V14"
}

Я почти справился с этим с помощью толчка (заменив шаг toUpper на шаг с добавлением желаемого «x»):

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "records": {
        "*": {
          "counters": "=split(' ',@(1,counters))",
          "values": "=split(' ',@(1,values))"
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "records": {
        "*": {
          "counters": { "*": "counters[]" },
          "values": { "*": "values[]" }
        }
      }
    }
  },
  { // ...concat() must instead of toUpper...
    "operation": "modify-overwrite-beta",
    "spec": {
      "counters": {
        "*": "=toUpper"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "counters": {
        "*": {
          "*": {
            "@(3,values[#2])": "&"
          }
        }
      }
    }
  }
]

, но не могу выполнить последний шаг - пробует все параметры, но concat возвращает либо «x», либо ItemX, но не xItemX ...

Спасибо

1 Ответ

0 голосов
/ 24 января 2020

Не уверен, что это именно то, что вам нужно, но вам не нужно использовать concat для добавления x к имени атрибута, просто добавьте x к правилу, после которого следует &:

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "records": {
        "*": {
          "counters": "=split(' ',@(1,counters))",
          "values": "=split(' ',@(1,values))"
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "records": {
        "*": {
          "counters": { "*": "counters[]" },
          "values": { "*": "values[]" }
        }
      }
    }
  },
  { 
    "operation": "modify-overwrite-beta",
    "spec": {
      "counters": {
        "*": "=toUpper"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "counters": {
        "*": {
          "*": {
            "@(3,values[#2])": "x&"
          }
        }
      }
    }
  }
]
...