AVRO Check

I am new to AVRO, so please excuse me if there is nothing obvious enough. Is there an AVR validator / commandline utility that validates input against an AVRO schema? Or probably indicates where the error is in the json input.

+5
source share
3 answers

Not that I knew. I wrote this little python script that will tell you if the json file matches the circuit, but it will not tell you where the error is, if any.

It depends on the Python avro library .

#!/usr/bin/env python

from avro.io import validate
from avro.schema import parse
from json import loads
from sys import argv

def main(argv):
    valid = set()
    invalid_avro = set()
    invalid_json = set()

    if len(argv) < 3:
        print "Give me an avro schema file and a whitespace-separated list of json files to validate against it."
    else:
        schema = parse(open(argv[1]).read())
        for arg in argv[2:]:
            try:
                json = loads(open(arg, 'r').read())
                if validate(schema, json):
                    valid.add(arg)
                else:
                    invalid_avro.add(arg)
            except ValueError:
                invalid_json.add(arg)
    print ' Valid files:\n\t' + '\n\t'.join(valid)
    print 'Invalid avro:\n\t' + '\n\t'.join(invalid_avro)
    print 'Invalid json:\n\t' + '\n\t'.join(invalid_json)

if '__main__' == __name__:
    main(argv)
+4
source

, : Avro Schema Avro, . , Avro .

, , Avro , ; . , : , , Schema, . , , .

+1

Avro JavaScript, JSON. Avro, . https://issues.apache.org/jira/browse/AVRO-485.

+1

All Articles