Member since
05-15-2020
2
Posts
1
Kudos Received
0
Solutions
05-18-2020
04:55 AM
1 Kudo
Great answer many thanks. For the record, I had the data in a FlowFile. I needed a bit of regex magic to remove the quotation marks after unescaping.
... View more
05-15-2020
06:39 AM
Hello, I have a CSV input similar to this, which I need in JSON. Name der Abteilung (DepartmentName),Name des Kontos (AccountName),ID des Kontobesitzers (AccountOwnerId),Zusätzliche Informationen (AdditionalInfo)
ExampleDepartment,,dnajas93477ajdn,"{ ""UsageType"": ""ComputeHR"", ""ImageType"": ""Windows Server BYOL""}" In the CSV there is a nice JSON embedded. I use an Avro Schema and the CSV Reader controller service to get rid of the human readable localized header and to read the the data. The Avro Schema currently looks like this: {
"type" : "record",
"name" : "DailyCSV",
"fields" : [
{ "name" : "DepartmentName" , "type" : ["string", "null"] },
{ "name" : "AccountName" , "type" : ["string", "null"] },
{ "name" : "AccountOwnerId", "type" : ["string", "null"] },
{ "name" : "AdditionalInfo", "type" : [ "null", "string" ] }
]
} This does reads the CSV nicely, however, the embedded JSON will be left as string, resulting following JSON: [ {
"DepartmentName" : ExampleDepartment,
"AccountName" : null,
"AccountOwnerId" : "dnajas93477ajdn",
"AdditionalInfo" : "{ \"UsageType\": \"ComputeHR\", \"ImageType\": \"Windows Server BYOL\"}
] What I would like to have is: [ {
"DepartmentName" : ExampleDepartment,
"AccountName" : null,
"AccountOwnerId" : "dnajas93477ajdn",
"AdditionalInfo" : {
"UsageType": "ComputeHR",
"ImageType": "Windows Server BYOL"
}
] Additional information: I do know the exact format of the JSON which gets embedded in this case. However, in the future I will have to tackle with user-generated tags which gets also stored as json arrays embedded in the CSV. There I will have no knowledge of the JSON field names (not even the number of them). Additional Info in the CSV can be empty. Any ideas?
... View more
Labels:
- Labels:
-
Apache NiFi