Skip to content

Commit bb722db

Browse files
authored
Merge pull request #164 from johnthagen/add-doc-example
Add a high level usage example to the docs
2 parents 49960a0 + 8d28228 commit bb722db

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

fastjsonschema/__init__.py

+27
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,33 @@
7272
* JSON schema says you can use keyword ``default`` for providing default values. This implementation
7373
uses that and always returns transformed input data.
7474
75+
Usage
76+
*****
77+
78+
.. code-block:: python
79+
80+
import fastjsonschema
81+
82+
point_schema = {
83+
"type": "object",
84+
"properties": {
85+
"x": {
86+
"type": "number",
87+
},
88+
"y": {
89+
"type": "number",
90+
},
91+
},
92+
"required": ["x", "y"],
93+
"additionalProperties": False,
94+
}
95+
96+
point_validator = fastjsonschema.compile(point_schema)
97+
try:
98+
point_validator({"x": 1.0, "y": 2.0})
99+
except fastjsonschema.JsonSchemaException as e:
100+
print(f"Data failed validation: {e}")
101+
75102
API
76103
***
77104
"""

0 commit comments

Comments
 (0)