validating and recording file paths in a JSON Schema

160 views
Skip to first unread message

Daniel Lenski

unread,
Oct 6, 2014, 8:03:19 PM10/6/14
to jsons...@googlegroups.com
Hi,
I'm using python-jsonschema to validate various input files for a data-warehousing application. Many of my input files refer to other external input files of various types (XML, SQL, custom binary formats, etc.) Here's an abbreviated example of a JSON schema which references an arbitrary number of files containing SQL queries, and an optional post-processing script:

    source_input_schema = dict(
        type="object",
        properties=dict(
            queries=dict(type='array', description='One or more SQL queries to execute',
                     items=dict(
                         type='object',
                         properties=dict(
                             sql=dict(type='string', title='File containing SQL query', format='external_file_path'),
                             db=dict(enum=list_of_databases),
                         ),
                         required = ['sql','db'],
                         additionalProperties = False,
                    ),
                    minItems=1,
                    uniqueItems=True,
            ),
            postproc=dict(type=['string','null'], title='Post-processing script', format='external_file_path')
        ),
        required = ['queries','postproc'],
        additionalProperties = False
    )

I'm trying to find an easy way to use the jsonschema validator to do the following with these references to external files:

1. Verify that they refer to valid, existing paths
2. Make a list of all the external files referenced so that they can be copied to a standard location, and then modify the reference to point to the new path in the JSON object.

I think (1) should be straightforward to do with FormatChecker, but I'm not sure if (2) is necessarily a standard use of the jsonschema validator, since it would require modifying the JSON object being validated while (or after) validating it.

I'm wondering if other jsonschema users have any advice or experience on how to do something like (2). Would it be better to modify the schema in-place while validating it? Or to modify it afterwards? Is there an easy way to iterate through the JSON object after validation and find all the properties that were validated with a specific format?

Thanks,
Dan Lenski
Reply all
Reply to author
Forward
0 new messages