需要在 YYYY-MM-DD-hh:mm:ss 中使用 JOLT sepc 转换日期 (12)

Need to convert date(12) with JOLT sepc in YYYY-MM-DD-hh:mm:ss

下面是输入json

[
  {
    "correlationId": "12345",
    "payloadFormat": "Money",
    "payload": {      
      "transactionDate": "2018010118060"      
      "name": "Dallas"      
    }
  },
  {
    "correlationId": "67895",
    "payloadFormat": "cash",
    "payload": {      
      "transactionDate": "2018010128040"      
      "name": "Texas"
      
    }
  }
]

下面是预期的输出

[
  {
    "correlationId": "12345",
    "payloadFormat": "Money",
    "payload": {      
      "transactionDate": "date should be in yyyy-MM-dd HH:mm:ss"      
      "name": "Dallas"      
    }
  },
  {
    "correlationId": "67895",
    "payloadFormat": "cash",
    "payload": {      
      "transactionDate": "date should be in yyyy-MM-dd HH:mm:ss"      
      "name": "Texas"
      
    }
  }
]

提供的输入中的 transactionDates 字符串似乎格式错误/不一致(长度不同,缺少秒数,请参阅答案末尾的第三个注释)。

输入稍作修改:

[
  {
    "correlationId": "12345",
    "payloadFormat": "Money",
    "payload": {
      "transactionDate": "201801011806012",
      "name": "Dallas"
    }
  },
  {
    "correlationId": "67895",
    "payloadFormat": "cash",
    "payload": {
      "transactionDate": "20180101084014",
      "name": "Texas"
    }
  }
]

规范:

[
  {
    "operation": "modify-default-beta",
    "spec": {
      "*": {
        "year": "=substring(@(1,payload.transactionDate),0,4)",
        "month": "=substring(@(1,payload.transactionDate),4,6)",
        "day": "=substring(@(1,payload.transactionDate),6,8)",
        "hour": "=substring(@(1,payload.transactionDate),8,10)",
        "minute": "=substring(@(1,payload.transactionDate),10,12)",
        "second": "=substring(@(1,payload.transactionDate),12,14)"
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "payload": {
          "transactionDate": "=concat(@(2,year),'-',@(2,month),'-',@(2,day),' ',@(2,hour),':',@(2,minute),':',@(2,second))"
        }
      }
    }
  },
  {
    "operation": "remove",
    "spec": {
      "*": {
        "year": "",
        "month": "",
        "day": "",
        "hour": "",
        "minute": "",
        "second": ""
      }
    }
   }
]

我们有如下输出:

[ {
  "correlationId" : "12345",
  "payloadFormat" : "Money",
  "payload" : {
    "transactionDate" : "2018-01-01 18:06:01",
    "name" : "Dallas"
  }
}, {
  "correlationId" : "67895",
  "payloadFormat" : "cash",
  "payload" : {
    "transactionDate" : "2018-01-01 08:40:14",
    "name" : "Texas"
  }
} ]

备注:

  1. 已通过 https://jolt-demo.appspot.com
  2. 测试
  3. 查看上面规范中也使用的 modify-default-beta 操作示例
  4. 如果 date(12) 中的 12 来自 post 的标题表示 transactionDate 的长度那么也许你的意思是 date(14): ( 4 + 2 + 2 + 2 + 2 + 2,意思是:年+月+日+时+分+秒)