ppb
ppb

Reputation: 2633

Jolt JSON Conversion from String value to Long

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

Upvotes: 3

Views: 3738

Answers (1)

Milo S
Milo S

Reputation: 4586

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.

Upvotes: 1

Related Questions