Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kroo/py-orderly-json
A python implementation of Orderly JSON
https://github.com/kroo/py-orderly-json
Last synced: 3 months ago
JSON representation
A python implementation of Orderly JSON
- Host: GitHub
- URL: https://github.com/kroo/py-orderly-json
- Owner: kroo
- Created: 2010-06-15T22:49:46.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2010-11-17T19:50:59.000Z (about 14 years ago)
- Last Synced: 2024-07-15T15:42:01.480Z (5 months ago)
- Language: Python
- Homepage: http://digital.gs/post/702660262/orderly-json-python-library
- Size: 3.37 MB
- Stars: 14
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# orderlyjson Python Library #
## Usage ##
>>> import orderlyjson, json
>>> orderlydoc = open('test.orderly').read()
>>> print orderlydoc
object {
string name;
string description?;
string homepage /^http:/;
integer {1500,3000} invented;
}*;>>> print json.dumps(
... orderlyjson.parse(orderlydoc), indent=4)
{
"additionalProperties": true,
"type": "object",
"properties": {
"invented": {
"minimum": 1500,
"type": "integer",
"maximum": 3000
},
"homepage": {
"pattern": "^http:",
"type": "string"
},
"name": {
"type": "string"
},
"description": {
"optional": true,
"type": "string"
}
}
}>>> jsondoc = open('test.json').read()
>>> print jsondoc
{
"name": "orderly",
"description": "A schema language for JSON",
"homepage": "http://orderly-json.org",
"invented": 2009
}>>> orderlyjson.validate(json.loads(jsondoc), orderlydoc)
>>> badjsondoc = """
... {
... "name": "orderly",
... "description": "A schema language for JSON",
... "homepage": "http://orderly-json.org",
... "invented": 4009
... }
... """
>>> orderlyjson.validate(json.loads(badjsondoc), orderlydoc)
Traceback (most recent call last):
File "", line 1, in
File "orderlyjson/__init__.py", line 13, in validate
jsonschema.validate(json_object, orderly_object)
File "orderlyjson/jsonschema/__init__.py", line 101, in validate
return v.validate(data,schema)
File "orderlyjson/jsonschema/validator.py", line 410, in validate
self._validate(data, schema)
File "orderlyjson/jsonschema/validator.py", line 413, in _validate
self.__validate("_data", {"_data": data}, schema)
File "orderlyjson/jsonschema/validator.py", line 439, in __validate
validator(data, fieldname, schema, new_schema.get(schemaprop))
File "orderlyjson/jsonschema/validator.py", line 128, in validate_properties
self.__validate(eachProp, value, properties.get(eachProp))
File "orderlyjson/jsonschema/validator.py", line 439, in __validate
validator(data, fieldname, schema, new_schema.get(schemaprop))
File "orderlyjson/jsonschema/validator.py", line 230, in validate_maximum
raise ValueError("Value %r for field '%s' is greater than maximum value: %f" % (value, fieldname, maximum))
ValueError: Value 4009 for field 'invented' is greater than maximum value: 3000.000000## Validation Tool ##
As a starting point, theres a short python script for validating a json file with
an associated orderly schema in the tools directory named `validate.py`; thanks to
**Jens Hübel** for the contribution:> Usage is then like this:
>
> 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']## Thanks and License ##
Thanks to **Lloyd Hilaiel** for the documentation and language specification at
[orderly-json.org](http://orderly-json.org/ "Orderly JSON").This code is licensed under the MIT license. It currently includes the
jsonschema library found [here](http://code.google.com/p/jsonschema/);