Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

NiFi CSV to Json with Json object string as value

avatar
Explorer

Hi, I am looking for the way to convert the CSV to JSON

I have a csv file with json object as value,

 

"name","item"

"david","{""currency"":""USD"",""content"":""Beauty Lips""}"

 

 

I used ConvertRecord processor with CSVReader and JsonRecordSetWriter

And the output JSON is

 

{
  "name":"david",
  "item":"{\"currency\":\"USD\",\"content\":\"Beauty Lips\"}"
}

 

But what I expected is

 

{
  "name":"david",
  "item":{"currency":"USD","name":"Beauty Lips"}
}

 

 

How can I archive this?

Thank you

 

David

1 ACCEPTED SOLUTION

avatar
Explorer

I re0rder the json to

 

 

 

{
  "item":{"currency":"USD","name":"Beauty Lips"},"name":"david"
}

 

 

 

I used ReplaceText processor

search value: "item":(.*),"name"

 

replace value: "item":${'$1':replaceFirst('"', ''):substringBeforeLast('"')},"name"

 

It does not look beauty but it works =/

 

My question is why I don't need to use unexcapeJson() like this?

"item":${'$1':replaceFirst('"', ''):substringBeforeLast('"'):unescapeJson()},"name"

View solution in original post

1 REPLY 1

avatar
Explorer

I re0rder the json to

 

 

 

{
  "item":{"currency":"USD","name":"Beauty Lips"},"name":"david"
}

 

 

 

I used ReplaceText processor

search value: "item":(.*),"name"

 

replace value: "item":${'$1':replaceFirst('"', ''):substringBeforeLast('"')},"name"

 

It does not look beauty but it works =/

 

My question is why I don't need to use unexcapeJson() like this?

"item":${'$1':replaceFirst('"', ''):substringBeforeLast('"'):unescapeJson()},"name"