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: how to validate JSON against Orderly


Hi folks,

 

having a validation tool would be great for defining the schema. I don’t know if anyone is going to try compiling the official C code or found a binary somewhere…. An alternative might be the python library from here:

https://github.com/kroo/py-orderly-json

 

For a simple case I tried this and it worked good. Here are the steps to take.

 

Install Python. Attention Use Python 2.7 and NOT Python 3!!!

http://www.python.org/download/

 

Download the zip file “kroo-py-orderly-json-eaaf3df.zip” from https://github.com/kroo/py-orderly-json and unpack this.

 

Add the parser and validator to the Python modules (you need the sub directory orderlyjson in the zip). I use the following file on Windows:

_setenv.bat:

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

set PYTHON_HOME=C:\Program Files\Python-2.7

set PATH=%PYTHON_HOME%;%PATH%

set PYTHONPATH=%PYTHON_HOME%\lib;C:\Jens \orderlyjson

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

 

I created the following three files:

PropDef.orderly (copied from our proposal):

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

  object {

       string  id;

       string  localName;

       string  localNameSpace?;

       string  displayName?;

       string  queryName?;

       string  description?;

       string  propertyType [ "string", "boolean", "decimal", "integer", "datetime", "uri", "id", "html" ];

       string  cardinality [ "single", "multi" ];

       string  updatability ["readonly", "readwrite", "whencheckedout", "oncreate" ];

       boolean inherited?;

       boolean required;

       boolean queryable;

       boolean openChoice?;

}*;

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

 

Invoice.json:

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

{

  "id": "4711",

  "localName": "InvoiceNo",

  "localNameSpace": "opencmis",

  "displayName": "Invoice Number",

  "queryName" : "INVOICE_NO",

  "description" : "Invoice Number Property Definition",

  "propertyType" : "string",

  "cardinality" : "single",

  "updatability" : "readwrite",

  "inherited" : false,

  "required" : true,

  "queryable" : true,

  "openChoice" : false

}

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

 

Invoice_bad.json (note the XXX):

{

  "id": "4711",

  "localName": "InvoiceNo",

  "localNameSpace": "opencmis",

  "displayName": "Invoice Number",

  "queryName" : "INVOICE_NO",

  "description" : "Invoice Number Property Definition",

  "propertyType" : "string",

  "cardinality" : "single",

  "updatability" : "XXX",

  "inherited" : false,

  "required" : true,

  "queryable" : true,

  "openChoice" : false

}

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

 

Then open a cmd prompt, call  _setenv.bat and enter python.exe:

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

>>> orderlydoc = open('PropDef.orderly').read()

 

>>> jsondoc = open('invoice.json').read()

>>> orderlyjson.validate(json.loads(jsondoc), orderlydoc)

(nothing happens means validation ok)

 

>>> jsondoc = open('invoice_bad.json').read()

>>> orderlyjson.validate(json.loads(jsondoc), orderlydoc)

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  … (omitted)

  File "orderlyjson\jsonschema\validator.py", line 309, in validate_enum

    raise ValueError("Value %r for field '%s' is not in the enumeration: %r" % ( value, fieldname, options))

ValueError: Value 'XXX' for field 'updatability' is not in the enumeration: ['readonly', 'readwrite', 'whencheckedout', 'oncreate']

 

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

 

I am not sure how complete and stable this is, but it might be more convenient than the HTML page. Perhaps some are interested in this and want to try it. I did not try more complex examples yet.

 

Jens

 



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