摇晃变换

时间:2018-01-16 16:21:00

标签: json jolt

我正在尝试为下面的输入写一个颠簸转换 -

{ 
 "restaurantId": "ZZ4ORJDY3E",  
 "chainId": "a-b"
}

预期产出是 -

{
 "ZZ4ORJDY3E" : {
   "key" : "ZZ4ORJDY3E",
   "start" : "a",
   "end" : "b"
  }
}

我的规格是 -

[
  {
    "operation": "shift",
    "spec": {
      "@restaurantId": "@restaurantId.key",
      "chainId": {
        "*-*": {
          "$(0,1)": "@restaurantId.start",
          "$(0,2)": "@restaurantId.end"
        }
      }
    }
  }
]

规范未按预期输出转换。我想学习如何在字符串解析器中使用属性。

1 个答案:

答案 0 :(得分:1)

规格

[
  {
    "operation": "shift",
    "spec": {
      "restaurantId": {
        // match any value of restaurantId
        "*": {
          // write the value to of the key $ to the output
          // where the output is the "value of the key".key
          // kinda hokey
          "$": "&.key"
        }
      },
      "chainId": {
        "*-*": {
          // write each part of the chainId to the output
          //  at the value of restaurantId from back up the tree
          "$(0,1)": "@(3,restaurantId).start",
          "$(0,2)": "@(3,restaurantId).end"
        }
      }
    }
  }
]