0
votes

I am using Apache NiFi and receive from an embedded micro over a TCP/IP socket a JSON file of the form:

{ "id": 123456, "ip": "192.168.1.1", "t": -12.9, "T": -23.8, "variables": [ "user1", 0, -12.97, 23.87 ] }

and would like to transform it such that the keys of the variables are added as they are known to me as follows:

{ "id": 123456, "ip": "192.168.1.1", "t": -12.9, "T": -23.8, "variables": [ "username" : "user1", "valid" : 0, "temperature 1" : -12.97, "temperature 2" : 23.87 ] }

and then to be able to access a key value pair such as variables.username.

I have tried using JoltTransformJSON but don't know how to write the spec correctly if it can do it!! I have written the following jolt spec:

[ { "operation": "shift", "spec": { "id": "id", "ip": "ip", "t": "t", "T": "T", "variables": { "username": "", "valid": "", "temperature 1": "", "temperature 2": "" } } } ]

I also have tried using UpdateRecord with Record Reader/Writer but passing the correct schema causes an error on the first variable as it can't match "user1" with a key from the initial JSON.

1
check JoltTransformJson processor - daggett
Have tried using JoltTransformJson processor but can't managed to get it working. Even tried using jolt-demo.appspot.com. I also have tried using UpdateRecord with Record Reader/Writer but passing the correct schema causes an error on the first variable - Jerry Pylarinos
please edit your question and provide your jolt transformation then maybe somebody will help you with it. also add a jolt tag/ - daggett

1 Answers

0
votes

I have managed to work out the Jolt Spec as follows:

[ { "operation": "shift", "spec": { "id": "id", "ip": "ip", "t": "t", "T": "T", "variables": { "0": "username", "1": "valid", "2": "temperature 1", "3": "temperature 2" } } } ]

Thank you daggett for your contribution.