OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

cmis-browser message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: RE: [cmis-browser] how to validate JSON against Orderly


Or a bit more convenient perhaps :

validate.py (use spaces, not tabs!):
############
import orderlyjson, json, sys;

def main(jsonFile, orderlyFile):
  orderlydoc = open(orderlyFile).read();
  jsondoc = open(jsonFile).read();
  
  try:
    orderlyjson.validate(json.loads(jsondoc), orderlydoc); 
    print "OK";
    return 0;
  
  except Exception as exc:
    print "Validation FAILED"; 
    print exc;
    return -1;
	
if __name__ == '__main__':
    main(sys.argv[1], sys.argv[2]);

############

And then in a command prompt:

python validate.py invoice.json PropDef.orderly

gives:
OK

or:
python validate.py invoice_bad.json PropDef.orderly

results in:
Validation FAILED
Value 'XXX' for field 'updatability' is not in the enumeration: ['readonly', 're adwrite', 'whencheckedout', 'oncreate']



validate.py



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]