json-structure 0.1.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- json_structure/__init__.py +302 -0
- json_structure/_version.py +34 -0
- json_structure/error_codes.py +615 -0
- json_structure/instance_validator.py +1191 -0
- json_structure/json_source_locator.py +373 -0
- json_structure/schema_exporter.py +561 -0
- json_structure/schema_validator.py +1055 -0
- json_structure-0.1.6.dist-info/METADATA +260 -0
- json_structure-0.1.6.dist-info/RECORD +11 -0
- json_structure-0.1.6.dist-info/WHEEL +4 -0
- json_structure-0.1.6.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: json-structure
|
|
3
|
+
Version: 0.1.6
|
|
4
|
+
Summary: Validators for JSON Structure schemas and instances
|
|
5
|
+
Project-URL: Homepage, https://json-structure.org
|
|
6
|
+
Project-URL: Documentation, https://github.com/json-structure/sdk
|
|
7
|
+
Project-URL: Repository, https://github.com/json-structure/sdk
|
|
8
|
+
Project-URL: Issues, https://github.com/json-structure/sdk/issues
|
|
9
|
+
Author-email: JSON Structure Project <info@json-structure.org>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
Keywords: json,json-structure,schema,type-system,validation
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Classifier: Topic :: Text Processing :: Markup
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.8
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# JSON Structure Python SDK
|
|
33
|
+
|
|
34
|
+
[](https://badge.fury.io/py/json-structure)
|
|
35
|
+
[](https://pypi.org/project/json-structure/)
|
|
36
|
+
[](https://opensource.org/licenses/MIT)
|
|
37
|
+
|
|
38
|
+
Python validators for [JSON Structure](https://json-structure.org) schemas and instances.
|
|
39
|
+
|
|
40
|
+
JSON Structure is a type-oriented schema language for JSON, designed for defining data structures
|
|
41
|
+
that can be validated and mapped to programming language types.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install json-structure
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Quick Start
|
|
50
|
+
|
|
51
|
+
### Validate a Schema
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from json_structure import SchemaValidator
|
|
55
|
+
|
|
56
|
+
schema = {
|
|
57
|
+
"$schema": "https://json-structure.org/meta/core/v0/#",
|
|
58
|
+
"$id": "https://example.com/person",
|
|
59
|
+
"name": "Person",
|
|
60
|
+
"type": "object",
|
|
61
|
+
"properties": {
|
|
62
|
+
"name": {"type": "string"},
|
|
63
|
+
"age": {"type": "int32"},
|
|
64
|
+
"email": {"type": "string"}
|
|
65
|
+
},
|
|
66
|
+
"required": ["name"]
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
validator = SchemaValidator()
|
|
70
|
+
errors = validator.validate(schema)
|
|
71
|
+
|
|
72
|
+
if errors:
|
|
73
|
+
print("Schema is invalid:")
|
|
74
|
+
for error in errors:
|
|
75
|
+
print(f" - {error}")
|
|
76
|
+
else:
|
|
77
|
+
print("Schema is valid!")
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Validate an Instance
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from json_structure import InstanceValidator
|
|
84
|
+
|
|
85
|
+
schema = {
|
|
86
|
+
"$schema": "https://json-structure.org/meta/core/v0/#",
|
|
87
|
+
"$id": "https://example.com/person",
|
|
88
|
+
"name": "Person",
|
|
89
|
+
"type": "object",
|
|
90
|
+
"properties": {
|
|
91
|
+
"name": {"type": "string"},
|
|
92
|
+
"age": {"type": "int32"}
|
|
93
|
+
},
|
|
94
|
+
"required": ["name"]
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
instance = {
|
|
98
|
+
"name": "Alice",
|
|
99
|
+
"age": 30
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
validator = InstanceValidator(schema)
|
|
103
|
+
errors = validator.validate_instance(instance)
|
|
104
|
+
|
|
105
|
+
if errors:
|
|
106
|
+
print("Instance is invalid:")
|
|
107
|
+
for error in errors:
|
|
108
|
+
print(f" - {error}")
|
|
109
|
+
else:
|
|
110
|
+
print("Instance is valid!")
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Features
|
|
114
|
+
|
|
115
|
+
### Supported Types
|
|
116
|
+
|
|
117
|
+
All 34 types from JSON Structure Core v0 are supported:
|
|
118
|
+
|
|
119
|
+
**Primitive Types:**
|
|
120
|
+
- `string`, `number`, `integer`, `boolean`, `null`
|
|
121
|
+
- `int8`, `uint8`, `int16`, `uint16`, `int32`, `uint32`
|
|
122
|
+
- `int64`, `uint64`, `int128`, `uint128` (string-encoded)
|
|
123
|
+
- `float8`, `float`, `double`, `decimal`
|
|
124
|
+
- `date`, `datetime`, `time`, `duration`
|
|
125
|
+
- `uuid`, `uri`, `binary`, `jsonpointer`
|
|
126
|
+
|
|
127
|
+
**Compound Types:**
|
|
128
|
+
- `object`, `array`, `set`, `map`, `tuple`, `choice`, `any`
|
|
129
|
+
|
|
130
|
+
### Extensions
|
|
131
|
+
|
|
132
|
+
- **Conditional Composition**: `allOf`, `anyOf`, `oneOf`, `not`, `if`/`then`/`else`
|
|
133
|
+
- **Validation Addins**: `minimum`, `maximum`, `minLength`, `maxLength`, `pattern`, etc.
|
|
134
|
+
- **Import Extension**: `$import`, `$importdefs` for schema composition
|
|
135
|
+
|
|
136
|
+
### Command Line Tools
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
# Validate a schema file
|
|
140
|
+
json-structure-check schema.json
|
|
141
|
+
|
|
142
|
+
# Validate an instance against a schema
|
|
143
|
+
json-structure-validate instance.json schema.json
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## API Reference
|
|
147
|
+
|
|
148
|
+
### SchemaValidator
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from json_structure import SchemaValidator
|
|
152
|
+
|
|
153
|
+
validator = SchemaValidator(
|
|
154
|
+
allow_dollar=False, # Allow '$' in property names
|
|
155
|
+
allow_import=False, # Enable $import/$importdefs
|
|
156
|
+
import_map=None, # Dict mapping URIs to local files
|
|
157
|
+
extended=False, # Enable extended validation features
|
|
158
|
+
external_schemas=None # List of schema dicts to sideload (matched by $id)
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
errors = validator.validate(schema_dict, source_text=None)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### InstanceValidator
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
from json_structure import InstanceValidator
|
|
168
|
+
|
|
169
|
+
validator = InstanceValidator(
|
|
170
|
+
root_schema, # The JSON Structure schema dict
|
|
171
|
+
allow_import=False, # Enable $import/$importdefs
|
|
172
|
+
import_map=None, # Dict mapping URIs to local files
|
|
173
|
+
extended=False, # Enable extended validation features
|
|
174
|
+
external_schemas=None # List of schema dicts to sideload (matched by $id)
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
errors = validator.validate_instance(instance)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Sideloading External Schemas
|
|
181
|
+
|
|
182
|
+
When using `$import` to reference external schemas, you can provide those schemas
|
|
183
|
+
directly instead of fetching them from URIs:
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
from json_structure import InstanceValidator
|
|
187
|
+
|
|
188
|
+
# External schema that would normally be fetched from https://example.com/address.json
|
|
189
|
+
address_schema = {
|
|
190
|
+
"$schema": "https://json-structure.org/meta/core/v0/#",
|
|
191
|
+
"$id": "https://example.com/address.json",
|
|
192
|
+
"name": "Address",
|
|
193
|
+
"type": "object",
|
|
194
|
+
"properties": {
|
|
195
|
+
"street": {"type": "string"},
|
|
196
|
+
"city": {"type": "string"}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
# Main schema that imports the address schema
|
|
201
|
+
main_schema = {
|
|
202
|
+
"$schema": "https://json-structure.org/meta/core/v0/#",
|
|
203
|
+
"$id": "https://example.com/person",
|
|
204
|
+
"name": "Person",
|
|
205
|
+
"type": "object",
|
|
206
|
+
"properties": {
|
|
207
|
+
"name": {"type": "string"},
|
|
208
|
+
"address": {"$ref": "#/definitions/Imported/Address"}
|
|
209
|
+
},
|
|
210
|
+
"definitions": {
|
|
211
|
+
"Imported": {
|
|
212
|
+
"$import": "https://example.com/address.json"
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
# Sideload the address schema - matched by $id
|
|
218
|
+
validator = InstanceValidator(
|
|
219
|
+
main_schema,
|
|
220
|
+
allow_import=True,
|
|
221
|
+
external_schemas=[address_schema]
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
instance = {
|
|
225
|
+
"name": "Alice",
|
|
226
|
+
"address": {"street": "123 Main St", "city": "Seattle"}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
errors = validator.validate_instance(instance)
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
You can supply multiple schemas to satisfy multiple imports. The schemas are matched
|
|
233
|
+
by their `$id` field against the import URIs.
|
|
234
|
+
|
|
235
|
+
## Development
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
# Clone the repository
|
|
239
|
+
git clone https://github.com/json-structure/sdk.git
|
|
240
|
+
cd sdk/python
|
|
241
|
+
|
|
242
|
+
# Install development dependencies
|
|
243
|
+
pip install -e ".[dev]"
|
|
244
|
+
|
|
245
|
+
# Run tests
|
|
246
|
+
pytest
|
|
247
|
+
|
|
248
|
+
# Run tests with coverage
|
|
249
|
+
pytest --cov=json_structure --cov-report=term-missing
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## License
|
|
253
|
+
|
|
254
|
+
MIT License - see [LICENSE](../LICENSE) for details.
|
|
255
|
+
|
|
256
|
+
## Links
|
|
257
|
+
|
|
258
|
+
- [JSON Structure Specification](https://github.com/json-structure/core)
|
|
259
|
+
- [JSON Structure Primer](https://github.com/json-structure/primer-and-samples)
|
|
260
|
+
- [SDK Repository](https://github.com/json-structure/sdk)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
json_structure/__init__.py,sha256=N_hMy3PMaFbZeCWPCt95qYm03Azwq3ctOMTSS2vKdFI,9660
|
|
2
|
+
json_structure/_version.py,sha256=riGXiVTWXmtdoju9hVCWvTxpszEMAAIK0sZZWoLKlnU,704
|
|
3
|
+
json_structure/error_codes.py,sha256=Esd13Bx72zO2PzvAtLJC15kn2lgPN0W3wuTYtcJ8TZ4,23469
|
|
4
|
+
json_structure/instance_validator.py,sha256=qoHC5ZpZWCOR2KDB4MoIYyeC0nfkzWt5vtdN33Eug7c,65964
|
|
5
|
+
json_structure/json_source_locator.py,sha256=bQjG-clksk-OJmUmQZZhhHb9duSbtcOA_iEpkR6M1Vo,12328
|
|
6
|
+
json_structure/schema_exporter.py,sha256=eySYTV7xOY2V979GSZa0OAWNhwIObTUOE_7O2Cdai-U,21288
|
|
7
|
+
json_structure/schema_validator.py,sha256=cUdox8aL6GGYc_5MutKxTTs3-ZIu2ZAIUmg_l4o3uzE,51312
|
|
8
|
+
json_structure-0.1.6.dist-info/METADATA,sha256=B8Yyeh7tOC04mW3vIzDh3wSz08Y4_9QeXloxGfZDePg,7275
|
|
9
|
+
json_structure-0.1.6.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
10
|
+
json_structure-0.1.6.dist-info/entry_points.txt,sha256=D0rxtU-KcwW8mdmPwXgEq9vlrOtsP_gJ1hP8tBZKbhM,143
|
|
11
|
+
json_structure-0.1.6.dist-info/RECORD,,
|