Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How to add a tag at the beginning of json with JoltTransformJson?

How to add a tag at the beginning of json with JoltTransformJson?

New Contributor

Hi, please, how to add a tag at the beginning of json with JoltTransformJson?

In the attached image I added a tag to the end of json, what syntax to add at startup?

94496-jolt.png


3 REPLIES 3

Re: How to add a tag at the beginning of json with JoltTransformJson?

Super Guru
@Julio Gazeta

I think you need to use another JoltTransformJson processor and keep your desired order of fields in this processor.

Example:

94505-screen-shot-2018-12-10-at-63947-pm.png

in the above example i have jolt spec with key values specified which order i need to get them in the resultant flow, same way you can keep your desired order in the second JoltTransformJSON processor.

You can also try using JoltTranfromRecord processor starting from NiFi-1.8 where we can specify Record Reader/Writer controller services as we can have desired order of fields.

In case if you are adding only one key/Value to your json message then consider UpdateRecord processor and keep your default values for Flag field and specify RecordReader/Writer controller services in this case you can add the field and arrange your fields in the desired order using only one processor.

Refer to this link for more details regards to UpdateRecord processor usage.

Re: How to add a tag at the beginning of json with JoltTransformJson?

Super Guru
@Julio Gazeta

If you are trying to add header/trailer to your existing JSON then try comparing between

ReplaceText processor vs JoltTrasnformProcessor

ReplaceText Configs:

Search Value

(?s)(^.*$)

Replacement Value

{ "messageType":["urn"], "message":{ "arquivo":$1 } }

Character Set

UTF-8

Maximum Buffer Size

1 MB //increase this value if flowfile size is more than 1 MB

Replacement Strategy

Regex Replace

Evaluation Mode

Entire text

94507-screen-shot-2018-12-10-at-82725-pm.png

By using ReplaceText processor we are adding header/trailer to the flowfile, i could say probably "JoltTransformRecord" processor will give most performance.

Please do load/performance test between JoltTransformJSON processors vs ReplaceText vs JoltTransformRecord (if you are using NiFi-1.8) and let us know which processor worked best for your case !!

Re: How to add a tag at the beginning of json with JoltTransformJson?

New Contributor

Hi Shu, in my case I just need to add a header and a trailler to my json? What would be the most performatic way to perform this procedure in nifi? Here is an example of the input of my json and how it should stay.

94506-example.png

Don't have an account?
Coming from Hortonworks? Activate your account here