Created 09-26-2023 05:42 AM
output file:
{
"name" : "name",
"class" : "a",
"grade" : "A",
"address" : "state"
"url" :{
"first url":"url",
"second url":"url"
}
}
Created 09-27-2023 07:20 AM
Assuming you have the following input where you can have multiple records per CSV input:
Name,class,grade,address,first_url,second_url
John,10th,A,New York,https://www.facebook.com,/brnds-coupons/offers
sam,9th,A,Dallas,www.google.com,www.amazon.com
You can use the following processors to do your transformation:
Where each processor is configured as the following:
- ConvertRecord: is to convert from CSV format to JSON
CSVReader: (use default settings)
Note: you can adjust the "Value Separator" in case the CSV delimiter is different from ",".
JSONRecorSertWriter: (use default settings)
- JoltTransformationJSON:
where "Jolt Specification" is set to the following:
[
{
"operation": "shift",
"spec": {
"*": {
"*": "[&1].&",
"first_url": "[&1].url.&",
"second_url": "[&1].url.&"
}
}
}
]
The output shouldlook like the following:
[
{
"Name": "John",
"class": "10th",
"grade": "A",
"address": "New York",
"url": {
"first_url": "https://www.facebook.com",
"second_url": "/brnds-coupons/offers"
}
},
{
"Name": "sam",
"class": "9th",
"grade": "A",
"address": "Dallas",
"url": {
"first_url": "www.google.com",
"second_url": "www.amazon.com"
}
}
]
if you need to process each record separately you can use SplitJson processor:
Use the "split" relationship to get the split records.
Hope that helps.
Created 09-26-2023 08:39 AM
@Abhiram-4455 Welcome to the Cloudera Community!
To help you get the best possible solution, I have tagged our NiFi experts @MattWho @cotopaul who may be able to assist you further.
Please keep us updated on your post, and we hope you find a satisfactory solution to your query.
Regards,
Diana Torres,Created 09-26-2023 11:24 AM
What's the input look like?
Created 09-26-2023 10:48 PM
Name, class, grade, address, first_url, second_url
John, 10th,A,New York,uhttps://www.facebook.com,/brnds-coupons/offers
Created 09-26-2023 11:44 AM
Hi @Abhiram-4455 ,
The easiest way to do such transformation is to use ConvertRecord to convert the format from CSV format to JSON format, then you can use JoltTransformation processor to do the proper transformation to the final format that you need. To see an example of this please refer to the following post: https://community.cloudera.com/t5/Support-Questions/want-to-convert-csv-to-nested-json-using-nifi/td...
If that helps please accept solution.
Thanks
Created 09-26-2023 10:50 PM
I have tried this example but getting errors like: unable to pares incoming data. Lot of errors... So can you help to get step by step process for which processor need to use and and configuration
Created 09-27-2023 07:20 AM
Assuming you have the following input where you can have multiple records per CSV input:
Name,class,grade,address,first_url,second_url
John,10th,A,New York,https://www.facebook.com,/brnds-coupons/offers
sam,9th,A,Dallas,www.google.com,www.amazon.com
You can use the following processors to do your transformation:
Where each processor is configured as the following:
- ConvertRecord: is to convert from CSV format to JSON
CSVReader: (use default settings)
Note: you can adjust the "Value Separator" in case the CSV delimiter is different from ",".
JSONRecorSertWriter: (use default settings)
- JoltTransformationJSON:
where "Jolt Specification" is set to the following:
[
{
"operation": "shift",
"spec": {
"*": {
"*": "[&1].&",
"first_url": "[&1].url.&",
"second_url": "[&1].url.&"
}
}
}
]
The output shouldlook like the following:
[
{
"Name": "John",
"class": "10th",
"grade": "A",
"address": "New York",
"url": {
"first_url": "https://www.facebook.com",
"second_url": "/brnds-coupons/offers"
}
},
{
"Name": "sam",
"class": "9th",
"grade": "A",
"address": "Dallas",
"url": {
"first_url": "www.google.com",
"second_url": "www.amazon.com"
}
}
]
if you need to process each record separately you can use SplitJson processor:
Use the "split" relationship to get the split records.
Hope that helps.
Created 09-28-2023 12:55 AM
Thank you so much SAMSAL it's working