0

I have JSONpayload like this;

 [ { "Samples" : { "Load" : [ { "dataItemId" : "a5", "timestamp" : "2019-02-17T04:58:44.097Z", "name" : "Aload", "sequence" : "19", "subType" : null, "content" : null }, { "dataItemId" : "a7", "timestamp" : "2019-02-17T04:58:44.097Z", "name" : "AAA", "sequence" : "19", "subType" : null, "content" : null } ], "Angle" : [ { "dataItemId" : "a6", "timestamp" : "2019-02-17T04:58:44.097Z", "name" : "Aact", "sequence" : "20", "subType" : "ACTUAL", "content" : null } ] } } ] 

I want to receive JSON like this;

{ "Samples" : [ { "tag_name": "Load", "dataItemId" : "a5", "timestamp" : "2019-02-17T04:58:44.097Z", "name" : "Aload", "sequence" : "19", "subType" : null, "content" : null }, { "tag_name": "Load", "dataItemId" : "a7", "timestamp" : "2019-02-17T04:58:44.097Z", "name" : "AAA", "sequence" : "19", "subType" : null, "content" : null }, { "tag_name": "Angle", "dataItemId" : "a6", "timestamp" : "2019-02-17T04:58:44.097Z", "name" : "Aact", "sequence" : "20", "subType" : "ACTUAL", "content" : null } ] } 

In my scenario, I must convert each json data defined above. I receive 500 JSON data per second. How can I do this using Jolt Specification? Do Jolt Specification fast? Do it suitable for streaming? Or Should I write my own script for this?

2
  • fast comparing to what? 500 JSON per second just increase the count of threads for this processor. suitable for streaming: jolt consumes and produces "hydrated" JSON - in-memory tree of Maps, Arrays, etc. ihmo: whatever you write would be comparable to jolt. Commented Feb 25, 2019 at 13:37
  • Is your JSON payload always an array with a single object? Commented Feb 25, 2019 at 19:35

1 Answer 1

3

This spec works if your payload is an array with a single object:

[ { "operation": "shift", "spec": { "*": { "Samples": { "*": { "*": { "$1": "Samples.&2[#2].tag_name", "*": "Samples.&2[#2].&" } } } } } }, { "operation": "shift", "spec": { "Samples": { "*": { "*": "Samples[]" } } } } ] 

Otherwise you might need to split the array, do the transform on each element, then use MergeContent or MergeRecord to get them back together. Alternatively you could use JoltTransformRecord which applies the spec to each element/record in the array, the spec would just need to changed to remove the initial * section in the first shift operation.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much! This is perfect for me. Jolt specification generally a little hard for me. I don't understand that how it works actually.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.