Python JSONSchema Objects Documentation
Python JSONSchema Objects Documentation
Release 0.0.18
Chris Wacek
Oct 07, 2017
Contents
1 What
3
2 Why
5
3 Other Features
7
4 Generating Multiple Top Level Objects
9
5 Installation
11
6 Tests
13
7 Changelog
15
8 API Documentation
17
8.1 Generated Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
i
ii
Python JSONSchema Objects Documentation, Release 0.0.18 python-jsonschema-objects provides an automatic class-based binding to JSON schemas for use in python.
Contents
1
Python JSONSchema Objects Documentation, Release 0.0.18
2
Contents
1 CHAPTER
What
python-jsonschema-objects provides an automatic class-based binding to JSON schemas for use in python. For example, given the following schema:
{ "title": "Example Schema", "type": "object", "properties": { "firstName": { "type": "string" }, "lastName": { "type": "string" }, "age": { "description": "Age in years", "type": "integer", "minimum": 0 }, "dogs": { "type": "array", "items": {"type": "string"}, "maxItems": 4 }, "address": { "type": "object", "properties": { "street": {"type": "string"}, "city": {"type": "string"}, "state": {"type": "string"} }, "required":["street", "city"] }, "gender": { "type": "string",
3
Python JSONSchema Objects Documentation, Release 0.0.18
"enum": ["male", "female"] }, "deceased": {
"enum": ["yes", "no", 1, 0, "true", "false"] } }, "required": ["firstName", "lastName"] }
jsonschema-objects can generate a class based binding. Assume here that the schema above has been loaded in a variable called schema:
>>> import python_jsonschema_objects as pjs >>> builder = pjs.ObjectBuilder(schema) >>> ns = builder.build_classes() >>> Person = ns.ExampleSchema >>> james = Person(firstName="James", lastName="Bond") >>> james.lastName u'Bond' >>> james
Validations will also be applied as the object is manipulated.
>>> james.age = -2 python_jsonschema_objects.validators.ValidationError: -2 was less or equal to than 0
The object can be serialized out to JSON:
>>> james.serialize() '{"lastName": "Bond", "age": null, "firstName": "James"}'
4
Chapter 1. What
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
Related searches
- python sort list of objects by attribute
- python pandas documentation pdf
- opencv python documentation pdf
- python generate documentation from docstrings
- python code documentation example
- python documentation in code
- python documentation for the len
- python documentation f string
- python documentation string
- python documentation string formatting
- python documentation for the len function
- python 3 documentation pdf