Created 08-28-2024 05:56 AM
Hi all!
i faced out with the problem.
I need to convert xml file to json.
here is my flow
ConvertRecord
XMLReader
JsonRecordSetWritter
Everything is ok, but the problem is in convetring digit-values
for example
xml data
<document_code>
<code>000</code>
</document_code>
converted to
"document_code": {
"code": 0
}
another one is:
<service-code>0012388833456</service-code>
converted to
"service-code": 12388833456
this is critical data, so i want Ni-Fi to convert them as string.
all values as string - is what i need.
Help please.
Created 08-28-2024 11:00 AM
@moshell281 Welcome to the Cloudera Community!
To help you get the best possible solution, I have tagged our NiFi experts @steven-matison @joseomjr 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 on 08-29-2024 05:12 AM - edited 08-29-2024 05:14 AM
@moshell281 This is indeed a very tough solution to solve. The only thing that comes to mind is creating your own schema, versus inferring the schema. Creating that schema from scratch could be a long task. So one trick you can do would be to run the flow to infer the schema, and configure the controller service to write that schema to an attribute. Inspect a flowfile and grab that schema. Next modify the schema to suit your needs, and then modify and test the flow with the specified schema (no longer inferred). This should allow you control to specify the correct data type for "000" so it is not assumed to be "0".
Created on 08-30-2024 05:54 AM - edited 08-30-2024 05:54 AM
Hi @moshell281 ,
@steven-matisonis right, when you use infer schema the processor will map the value as it thinks the data type should be, so if it sees an integer it will map to an integer and so on. To force certain datatypes you have to define your own Avro schema and feed it to the Json Record Set Writer since this is your target format. If you are not comfortable working with Avro schema then you can use UpdateRecord or even JsonJoltTransformation processors to cast the value into the proper type.
Hope you find this helpful.
Created 09-11-2024 06:17 AM
@moshell281 Has the reply helped resolve your issue? If so, please mark the appropriate reply as the solution, as it will make it easier for others to find the answer in the future. Thanks.
Regards,
Diana Torres,