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).

Following 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_12-1594216925111.png
  2.  Click the Record Reader value and select Create New Service.
  3. Select JSONTreeReader and click CREATE.
    Barsha_13-1594216925263.png
  4.  Similarly, click on the Record Writer value and select Create New Service.
  5. Select XMLRecordSetWriter and click CREATE.
    Barsha_14-1594216925439.png
  6. Final configuration of ConvertRecord should look like this:
    Barsha_15-1594216925545.png
  7. Click à to configure JSONTreeReader to configure details about the schema that should be read by the registry. The controller service form should open:
    Barsha_16-1594216925656.png
  8. Click configure of JSONTreeReader to start configuring the JSON Reader and configure as per the following screenshot:
    Barsha_17-1594216925856.png
  9. When you select Create New Service in the above screenshot, another form opens up. Fill it up based on the following screenshot and click CREATE:
    Barsha_18-1594216926188.png
  10. Fill in the rest of the information as follows:
    Barsha_19-1594216926429.png
  11. Click à arrow next to AvroSchemaRegistry and now the controller service page would look like this:
    Barsha_20-1594216926648.png
  12. Click configure 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_21-1594216926766.png
  13. Apply and enable the AvroSchemaRegistry and JSONTreeReader from the controller service.
  14. Click configure on XMLRecordSetWriter in controller service and configure as follows:
    Barsha_22-1594216926961.png
  15. Finally, ensure setting a new property to let the ConvertRecord know the schema name as follows in UpdateAttribute processor before sending the JSON message to ConvertRecord:
    Barsha_23-1594216927123.png
1,722 Views
0 Kudos