- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
NiFi CSV to Json with Json object string as value
- Labels:
-
Apache NiFi
Created on
09-27-2019
09:36 PM
- last edited on
09-28-2019
03:03 AM
by
ask_bill_brooks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Created on 09-30-2019 03:45 PM - edited 09-30-2019 05:17 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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"
Created on 09-30-2019 03:45 PM - edited 09-30-2019 05:17 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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"
