Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jolt JSON Conversion from String value to Long

Tags:

jolt

I am using Jolt to convert one json to another json. Everything is working fine except I want to convert String value to Long. Below is my Specs and input. I have use modify-overwrite-beta but no luck.

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",
}

So in above input json how I can convert time value to Long

Expected Json :

{
   "outputText1": "test1",
   "timestamp": 1499967627,
   "outputText2": "test2",
   "outputText3": "test3",
}
like image 987
ppb Avatar asked May 17 '26 21:05

ppb


1 Answers

Spec

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

In the first operation (modify) it was making "timestamp" be a long. But then in the 2nd operation, you were copying the String value from "time" to timestamp, instead of passing timestamp thru.

like image 55
Milo S Avatar answered May 23 '26 01:05

Milo S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!