Jolt JSON从String值转换为Long

时间:2017-07-19 00:43:25

标签: jolt

我正在使用Jolt将一个json转换为另一个json。除了我想将String值转换为Long之外,一切正常。以下是我的规格和输入。我使用 modify-overwrite-beta 但没有运气。

Specs -  

[  
  {
    "operation": "modify-overwrite-beta",
    "spec": {
       "timestamp": "=toLong(@(1,time))"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "key1": "outputText1",
      "key2": "outputText2",
      "key3": "outputText3",
      "time": "timestamp"     
   }
 }
]

Input Json

{
   "key1": "test1",
   "time": "1499967627",
   "key2": "test2",
   "key3": "test3",
}

所以在上面的输入json中我如何将时间值转换为 Long

预计Json:

{
   "outputText1": "test1",
   "timestamp": 1499967627,
   "outputText2": "test2",
   "outputText3": "test3",
}

1 个答案:

答案 0 :(得分:1)

规格

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "timestamp": "=toLong(@(1,time))"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "key1": "outputText1",
      "key2": "outputText2",
      "key3": "outputText3",
      // pass timestamp thru
      "timestamp": "timestamp"
    }
  }
]

在第一个操作(修改)中,正在制作"时间戳"很长但是在第二个操作中,你是从"时间"复制String值。到时间戳,而不是通过时间戳。