Support Questions

Find answers, ask questions, and share your expertise

nifi - incorrect json format correction

avatar

78518-1.jpg

78521-3.jpg

Hello,

I am taking data in xml format using SOAP-Request.

78524-4.jpg

stylesheet.zip

I convert the incoming xml data to json format through the Stylesheet XML file using the TransformXML processor.

but in the json file that is created after the conversion, I am getting the wrong json format warning because I am marked as yellow ".

incorrect

78522-2.jpg

{ "soap:Envelope": { "soap:Body": { "Musteri_Hiyerarsi_TablosuResponse": { "Musteri_Hiyerarsi_TablosuResult": "[ { "UNIQ_KEY": 740281.0, "TTALT": 112.0, "TTAD": "TEST" } ]" } } } }

"sign cleared

78523-3.jpg

{ "soap:Envelope": { "soap:Body": { "Musteri_Hiyerarsi_TablosuResponse": { "Musteri_Hiyerarsi_TablosuResult": [ { "UNIQ_KEY": 740281.0, "TTALT": 112.0, "TTAD": "TEST" } ] } } } }

I ask you for your help on how to remove the character.

ek'te

thank you.

7 REPLIES 7

avatar
Master Guru
@Murat Menteşe

You can use ReplaceText processor after TransformXml processor then add the matching regex excluding "(quotes) before/after array [].

ReplaceText Configs:-

Search Value

(.*)"(\[.*\])"(.*)

Replacement Value

$1$2$3

Character Set

UTF-8

Maximum Buffer Size

1 MB //increase the size according to your flowfile size

Replacement Strategy

Regex Replace

Evaluation Mode

Entire text

78526-replacetext.png

Input:-

{ "soap:Envelope": { "soap:Body": { "Musteri_Hiyerarsi_TablosuResponse": { "Musteri_Hiyerarsi_TablosuResult": "[ { "UNIQ_KEY": 740281.0, "TTALT": 112.0, "TTAD": "TEST" } ]" } } } }

Output: valid json

{ "soap:Envelope": { "soap:Body": { "Musteri_Hiyerarsi_TablosuResponse": { "Musteri_Hiyerarsi_TablosuResult": [ { "UNIQ_KEY": 740281.0, "TTALT": 112.0, "TTAD": "TEST" } ] } } } }

avatar
Master Guru
@Murat Menteşe

Could you share your sample xml file data so that i can reproduce the issue on my side by converting to json format?

avatar

@Shu

hello,

ReplaceText process data did not work on large data.

I am posting a larger example of the data in the attachment. If you can help it very much but very much.xml-to-json.zip

avatar
Master Guru
@Murat Menteşe

As your xml doc having array [] in it and i'm not sure how to write matching xslt. As the current xslt converts the array xml into object/element and adding "" for array[].

In case of large data you have to increase the

Maximum Buffer Size

1 MB //increase based on your flowfile size

as this processor works takes the whole flowfile into memory and does all replacing based on our configs.

avatar

thank you for your help. it worked. but as an example I rolled this json format. Normally it will be over 100mb. the error is still the same.But this solution can be a quick solution. can not you do anything to correct this problem in the incoming xml file Stylesheet? note: I have not been able to experiment on large data yet because it is in the test phase.

avatar

Of course, you can find the work file as an attachment. thank you so much.

xml-to-json.xml

style.zip

avatar
New Contributor

This is the best steps to resolve the problem with the XML. you can resolve the problem in nifi. And if you are using any home appliances like fridge and washing machine then you can coordinate with geek squad support UK 24*7.