JOLT change string to float

这一生的挚爱 提交于 2021-01-28 12:20:26

问题


Input JSON

{
  "sId": "1000000000000000",
  "lat": "12.934638",
  "lon": "77.693950",
  "status": "up",
  "last_change": 1503452208
}

My design spec:

[
   {
      "operation":"shift",
      "spec":{
         "Id":"Id",
         "status":"status",
         "last_change":"last_change",
         "lat":{
            "@(2,lat)":{
               "@(2,lat)":"geocoordinate.coordinates[0]"
            }
         },
         "lon":{
            "@(2,lon)":{
               "@(2,lon)":"geocoordinate.coordinates[1].",
               "#Point":"geocoordinate.type"
            }
         }
      }
   }
]

as lat long is coming as string but in output i want to have it as float. i tried conversion function but couldn't get expected result. please help me to change the lat long value into float.


回答1:


Use a "modify" as your first operation to do the type conversion first, then do you shift.

Spec

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "lat": "=toDouble",
      "lon": "=toDouble"
    }
  }
]

Also type conversion example here http://jolt-demo.appspot.com/#modify-typeConversion



来源:https://stackoverflow.com/questions/46224488/jolt-change-string-to-float

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!