Support Questions

Find answers, ask questions, and share your expertise

How to convert key value string to json in NiFi

New Contributor

Hi, I have a json object as input, however one of its elements is a string that contains keys and values.
I would like to convert this string to json.

For example, my input json is:

{"name" : "John",

"empID" : "1234",

"additionl_information" : "age=29;height=1.80"


And the output should be:

{"name" : "John",

"empID" : "1234",

"age" : "29",

"height" : "1.80"


The key/value pairs are delimited with ";".

And most important is that we don't know in advance what will be the keys inside the "addition_information" parameter. We have "age" and "height" in one event, but in another event we can get other information.

Many thanks in advance.


New Contributor

@Yoel Barsheshet

You can use a replacetext processor with a regular expression as in this example I did for you



Example input flowfile


After the replacetext processor with the above configuration


New Contributor

You have to use a replace text Processor and configure it in the following way

ReplaceText Processor will replace content in the flowfile based on a regular expression match.


Everything that matches the regular expression will be replaced.

The key of the regular expression is the use of parentheses (), in the way that the content of the first parentheses can be referenced later as $1 and the content of the second parentheses can be referenced as $2.


Based on your example this is the content of the incoming flowfile


And this the result after the ReplaceText processor with the above configuration


New Contributor

Thank you @Mariano Billinghurst

One of the challanges that I have is that I don't know in advance what are the key names. So in the above example, I don't know in advance that I will get inside the "additional_information" the "age" and "hight" keys. This part is dynamic.

Do you know how it can be supported?

New Contributor

Then use several replacetext processor in a chain

1st Processor

replace :

 "additionl_information" :
(empty string)

2nd processor




" : "

3rd Processor





note: for the (newline) you should actually should hit shift+enter to get the new line in the nifi processor