1
votes

Am trying to write specs to transform a json using Jolt transformation

Input:

{
    "video": "10506207",
    "id": "ef3ef821-92cb-441b-b218-c10e543398e3",
    "session": "a7a55e610a813c36",
    "time-in": 180,
    "event": "init"
}

Output

{
    "video": "10506207",
    "id": "ef3ef821-92cb-441b-b218-c10e543398e3",
    "session": "a7a55e610a813c36",
    "events":[
       "event": "init",
       "time-in": 180,
       "time-out": 120,  (= time-in - 60)
    ]
 }

Basically trying two things: 1. Move 'time-in' and 'event' attributes to 'events' array 2. Add 'time-out' = time-in - 60

With 'default' operation I could add attributes but couldn't do mathematical operations. Thanks for any help!

1
Also, if its possible to calculate 'time-out' based on condition, like if(time-in>0) time-in - 60 else 0 - Sammy
If you're doing this within Apache NiFi (one of your other recent questions was about NiFi), you can do this via the Expression Language with a ReplaceText processor. - Andy

1 Answers

1
votes

The fancy "time-out = time-in -60" is not supported by Jolt. But it can move the data around so that it matches the desired output format, minus the "time-out" calculation.

Spec [ { "operation": "shift", "spec": { "video": "video", "id": "id", "session": "session", "time-in": "events[0].time-in", "event": "events[0].event" } } ]