Skip to main content
mstfo
Gold ⭐️
Apr 2, 2024 8:25 AM UTC
Question

How can i parse string nested json with Nifi?

Hello,

I have a JSON data in the ClickHouse database with a type of string. The JSON data looks like this:

 

[{ "Name": "Gta V" "Type": "Xyz" "content": "{"Game":{"Subject":[{"Time":{"@value":"201511021057"}}]}}" }]

 

The output I get using Nifida ExecuteSqlRecord is like this. I can remove the \ character using the ReplaceText process. The output looks like this: 

 

[{ "Name": "Gta V" "Type": "Xyz" "content": "{"Game":{"Subject":[{"Time":{"@value":"201511021057"}}]}}" }]

 

However, the value part for the content key is still a string. How can I make its type as JSON?

The desired output is like this:

 

[{ "Name": "Gta V" "Type": "Xyz" "content": {"Game":{"Subject":[{"Time":{"@value":"201511021057"}}]}} }]

 



7 replies

saquibsk
Gold ⭐️⭐️
Apr 2, 2024 2:48 PM UTC

HI @mstfo,

Take the output to UpdateRecord processor, and cast the desire field to any specific data type example

formula: ${field.value:ToInteger()}

Translate
Shakib M.
mstfo
mstfoAuthor
Gold ⭐️
Apr 3, 2024 6:50 AM UTC

I am currently using the 'executesqlrecord -> replacetext' (for unescapeJson) process. How should I use the 'updateRecord' processor here? Could you explain a bit more ?

Translate
saquibsk
Gold ⭐️⭐️
Apr 3, 2024 7:56 AM UTC

Are you fetching and processing the records as it is ? or defining the json path (flatting the JSON) ?

 

[{ "Name": "Gta V" "Type": "Xyz" "content": "{"Game":{"Subject":[{"Time":{"@value":"201511021057"}}]}}" }]

 

Translate
Shakib M.
mstfo
mstfoAuthor
Gold ⭐️
Apr 3, 2024 8:45 AM UTC

 

The content field in the source table is in string format. When I receive the data from the source, it comes like this:

[{ "Name": "Gta V" "Type": "Xyz" "content": "{"Game":{"Subject":[{"Time":{"@value":"201511021057" }}]}}" }]

 

 

 

After I fetch this data with NiFi, I need to use a Jolt transformation on the content field, but since the content field is in string format, I can't perform the transformation. My actual problem is to eliminate the string expression in the content field and convert it to the following format so that I can use Jolt for the content field:
 
 

 

[{ "Name": "Gta V" "Type": "Xyz" "content": {"Game":{"Subject":[{"Time":{"@value":"201511021057"}}]}} }]

 

Translate
saquibsk
Gold ⭐️⭐️
Apr 3, 2024 7:46 PM UTC

Can you send the JOLT just to understand what you are exactly extracting?

for example if you are extracting @value  then something like "@value": "=toInteger" in JOLT can be written for typeconversion.

I belive type conversion can not be done in list.

Translate
Shakib M.