File: json-schema.md

package info (click to toggle)
python-strictyaml 1.7.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,708 kB
  • sloc: python: 12,836; sh: 48; makefile: 3
file content (49 lines) | stat: -rw-r--r-- 1,307 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
---
title: Why not use JSON Schema for validation?
---

JSON schema can also be used to validate YAML. This presumes that
you might want to use jsonschema and yaml together.

StrictYAML was inspired by the frustration of trying to use
pyyaml with [pykwalify](https://pykwalify.readthedocs.io/),
in fact.

## Loss of line numbers

Because parsing first with pyyaml and then passing the result
to pykwalify loses line numbers, validation errors lose the
line number where the validation error occurred.

This makes tracking down the location of errors tricky. If
a schema is a little repetitive it can make tracking down
the exact location of the error hellish.

# Simpler errors in StrictYAML

StrictYAML has an emphasis on the friendliness of schema
validation errors. Ideally every schema validation error
should be extremely obvious and show only the information
necessary.

# StrictYAML schemas are more flexible

Because schemas are written in python and strictyaml allows
revalidation, strictyaml schemas are much more flexible:

Example:

```python
from strictyaml import load, Seq, Enum
import pycountry    # updated list of country codes


load(
    strictyaml_string,
    Map(
        {
            "countries": Seq(Enum([country.alpha_2 for country in pycountry.countries]))
        }
    )
)
```