URGENT HELP on nested JOLT
See original GitHub issueHI All,
Is there an easy way to capture object index ?
INPUT:
{ "header": { "namespace": "someNamespace", "version": "1" }, "body": { "dataM": { "sourceM": [ { "name": "State", "type": "string" }, { "name": "City", "type": "string" }, { "name": "var", "type": "string" }, { "name": "unit", "type": "string" }, { "name": "type", "type": "string" } ], "valueM": [ { "name": "timestamp", "type": "date-time" }, { "name": "value", "type": "string" }, { "name": "quality", "type": "integer" }, { "name": "error", "type": "string" } ] }, "data": [ { "source": [ "Austria", "Vienna", "temp", "F", "now" ], "values": [ [ "2018-10-02T15:00:00.05Z", "3.1234", 7, "SomeError" ], [ "2018-10-02T15:00:46.05Z", "3.221", 0, "SomeOtherError" ] ] }, { "source": [ "Germany", "Berlin", "pressure", "PA", "now" ], "values": [ [ "2018-10-02T16:00:00.05Z", "5", 0, "NoError" ] ] } ] } }
spec:
[{ "operation": "shift", "spec": { "body": { "data": { "*": { "@(4,header)": { "*": "newdata[&2].&" }, "source": { "*": "newdata.[&2].@(4,dataM.sourceM.[&].name)" }, "values": { "*": { "*": "newdata.[&3].@(5,dataM.valueM[&].name)" } } } } } } } , { "operation": "shift", "spec": { "newdata": { "*": "[&0]" } } } ]
Desired Output:
[ { "namespace" : "someNamespace", "version" : "1", "State" : "Austria", "City" : "Vienna", "var" : "temp", "unit" : "F", "type" : "now", "timestamp" :"2018-10-02T15:00:00.05Z", "value" : "3.1234", "quality" : 7, "error" : "SomeError" }, { "namespace" : "someNamespace", "version" : "1", "State" : "Austria", "City" : "Vienna", "var" : "temp", "unit" : "F", "type" : "now", "timestamp" : "2018-10-02T15:00:46.05Z" , "value" : "3.221" , "quality" : 0, "error" : "" },{ "namespace" : "someNamespace", "version" : "1", "State" : "Germany", "City" : "Berlin", "var" : "pressure", "unit" : "PA", "type" : "now", "timestamp" : "2018-10-02T16:00:00.05Z", "value" : "5", "quality" : 0, "error" : "NoError" } ]
Currently, I’m getting arrays for timestamp, value, quality and error for each object. Instead, I need source array repeated per number of values within the data object.
@mattyb149 @milosimpson can anyone help? @niernier007 @theamitojha
Issue Analytics
- State:
- Created 4 years ago
- Comments:9
Seems like * is being removed while pasting it here please add left hand side.
[ { “operation”: “shift”, “spec”: { “body”: { “data”: { “": { “values”: { "”: { “@(5,header.namespace)”: “newdata.box.namespace”, “@(5,header.version)”: “newdata.box.version”, “@(2,source)”: { “": “newdata.box.@(6,dataM.sourceM.[&].name)” }, "”: “newdata.box.@(5,dataM.valueM.[&].name)” } } } } } } }, { “operation”: “shift”, “spec”: { “newdata”: { “box”: { “": { "”: “[&].&1” } } } } } ]
@nenyri, please check out if it is what you ment: