Question

Validate a JSON file against a specified schema

  • 15 April 2023
  • 4 replies
  • 22 views

JSON2ValidateSchemaI have a schema JSON file that I want to use to validate various JSON files. What transformers can I use to perform this functionality? JSON Validator only validates syntax and not schema so what's the alternative for this?

I have added pictures of the sample JSON schema and also the JSON file that needs to be validated against that schema.


4 replies

Userlevel 3
Badge +16

A basic way could be to use a JsonExtractor to pick out certain attributes in the json, AttributeValidator to see if they have values. That won't work though if you're expecting there to be empty values.

A more complete approach could be a JsonFlattener with a SchemaScanner perhaps.

Userlevel 5
Badge +29

A basic way could be to use a JsonExtractor to pick out certain attributes in the json, AttributeValidator to see if they have values. That won't work though if you're expecting there to be empty values.

A more complete approach could be a JsonFlattener with a SchemaScanner perhaps.

An approach along similar lines could be to read in the JSON Schema File with a FeatureReader set to only read schema, then concat the list down to a single attribute. Then read your other JSON files in (getting the schema as well) and repeat the same with the schema and check that the two result schemas (from your JSON Schema File and JSON Data) are the same

An approach along similar lines could be to read in the JSON Schema File with a FeatureReader set to only read schema, then concat the list down to a single attribute. Then read your other JSON files in (getting the schema as well) and repeat the same with the schema and check that the two result schemas (from your JSON Schema File and JSON Data) are the same

Thanks for your response. How do I concat the list (also which list to be concatenated?) ? I'm getting fme_feature_type_name,format_short_name. long_name & schema_handling as output of the schema of Feature reader. I've shared screenshots of the workbench. Please have a look and suggest.IMG-9555IMG-9554IMG-9553IMG-9552

A basic way could be to use a JsonExtractor to pick out certain attributes in the json, AttributeValidator to see if they have values. That won't work though if you're expecting there to be empty values.

A more complete approach could be a JsonFlattener with a SchemaScanner perhaps.

Thanks for the response @ctredinnick​ . I have shared a sample schema and JSON file. I need to validate the file against the schema. Please have a look and suggest the best possible approach.

Reply