Community Articles

Find and share helpful community-sourced technical articles.
Labels (2)
avatar
Explorer

In order to convert JSON to XML, you can use ConvertRecord processor available as part of the NiFi tool (I worked on version: 1.11.4).

Here are the steps to configure ConvertRecord processor to convert JSON input to XML output:

  1. Add a processor – ConvertRecord and right-click to “configure”:Barsha_0-1594310560144.png
  2. Click on the “Record Reader value” and select “Create New Service”. Select “JSONTreeReader” and click CREATE:
    Barsha_1-1594310560308.png
  3. Similarly, Click on the “Record Writer value” and select “Create New Service”. Select “XMLRecordSetWriter” and click CREATE:
    Barsha_2-1594310560495.png
  4. Final configuration of Convert Record should look like this:
    Barsha_3-1594310560582.png
  5. Click on “à to configure “JSONTreeReader” to configure details about the schema which should be read by the registry. The controller service form should open:
    Barsha_4-1594310560686.png
  6. Click on “configure icon” of “JSONTreeReader” to start configuring the JSON Reader and configure as per below screenshot:
    Barsha_5-1594310560832.png
  7. When you select “Create New Service” in the above screenshot, another form opens up. Fill it up based on below screenshot and click CREATE:
    Barsha_6-1594310561007.png
  8. Fill in rest of the information as:
    Barsha_7-1594310561148.png
  9. Click on à arrow next to “AvroSchemaRegistry” and now the controller service page would look like this:
    Barsha_8-1594310561266.png
  10. Click on “configure icon” against “AvroSchemaRegistry” and configure the registry. Add a new property with any schema name (for example, my_schema), and property value should be an AVRO schema that your JSON reader should read. In this case, you can take JSON message and using any online tool, create an AVRO schema, and paste it here. You can create AVRO schema using an online tool (I used this one: AVRO schema generator)
    Barsha_9-1594310561345.png
  11. Apply and enable the “AvroSchemaRegistry” and “JSONTreeReader” from controller service.
  12. Click on “configure icon” on “XMLRecordSetWriter” in controller service and configure as below:
    Barsha_10-1594310561558.png
  13. Finally, make sure to set a new property to let the ConvertRecord know the schema name as below in UpdateAttribute processor before sending the JSON message to ConvertRecord:
    Barsha_11-1594310561695.png

 

4,083 Views
Comments
avatar
Contributor

Thanks for this excellent post, it works almost perfect in 1.13.0 version.

The only problem I had was when did the last step (13) and the ConvertRecord processor became invalid with the following message:

 

templarian_1-1623286811368.png

 

I found the solution to this issue in this post of @pvillard where he updates the schema.name property before de ConvertRecord processor. I didn't complete understand the reason but it works.