Jolt transformation to move few attributes to an array

1.6k views Asked by At

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

There are 1 answers

2
Milo S On

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