Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

NIFI : Validating JSON transformation with JSON SCHEMA

NIFI : Validating JSON transformation with JSON SCHEMA

New Contributor

I realize that there is already an XML to JSON Schema Transformation as posted here:

https://community.hortonworks.com/articles/29474/nifi-converting-xml-to-json.html (XML to JSON).

1) What I am curious to "create" is a data flow that can validate a transformed JSON document the same way the ValidateXML processor validates an XML document. So basically transform the xml to JSON correctly, but also translate an XSD (schema) to a JSON (schema) and have it validate and produce the same results that the XML would, but just in JSON.

My Ideas: Transform the xml document into JSON and then ingest into MongoDB and use the document validation within MongoDB to validate the JSON?

If this becomes more of a discussion, I would love to hear it.

4 REPLIES 4

Re: NIFI : Validating JSON transformation with JSON SCHEMA

New Contributor

Here are some possibilities I am finding: For the conversion part, use this XSLT to transform the XML in to JSON via the TransformXml processor.

*A ValidateJson processor is in the works under NIFI-1893*, in the meantime you can use ExecuteScript with the approach in this post, or use ExecuteStreamCommand. ~mattyb (stackoverflow)

Re: NIFI : Validating JSON transformation with JSON SCHEMA

Hi @Alexander Brown

I've had success transforming the XML to JSON and then converting the JSON into Avro schema - where the JSON schema will need to adhere to the Avro schema. You can generate an Avro schema from your existing JSON by running the InferAvroSchema processor

From that XML to JSON XSLT - I'd use https://www.bjelic.net/2012/08/01/coding/convert-xml-to-json-using-xslt/#code and not the example posted (as I posted in the comments)

Re: NIFI : Validating JSON transformation with JSON SCHEMA

New Contributor

Thank you @Ryan Cicak ,but before I accept this as an answer, I would just like some clarification. I think you are suggesting two things here. First, that 1) I transform the XML file to JSON by applying the XSLT @ https://www.bjelic.net/2012/08/01/coding/convert-xml-to-json-using-xslt/#code which I am familiar with doing.

I am confused about 2) how to transform the XML Schema to JSON (or AVRO schema, as suggested) in order for the new JSON/AVRO schema to evaluate the JSON document that was changed by the XSLT to produce the same results as the XML Schema evaluating the XML FILE.

Highlighted

Re: NIFI : Validating JSON transformation with JSON SCHEMA

New Contributor

Avro schema is very limited if you are looking for more complex validations that XML Schema or JSON schema can provide.