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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
---
title: Parsing YAML without a schema
---
When using strictyaml you do not have to specify a schema. If
you do this, the validator "Any" is used which will accept any
mapping and any list and any scalar values (which will always be
interpreted as a string, unlike regular YAML).
This is the recommended approach when rapidly prototyping and the
desired schema is fluid.
When your prototype code is parsing YAML that has a more fixed
structure, we recommend that you 'lock it down' with a schema.
The Any validator can be used inside fixed structures as well.
Example yaml_snippet:
```yaml
a:
x: 9
y: 8
b: 2
c: 3
```
```python
from strictyaml import Str, Any, MapPattern, load
from ensure import Ensure
```
Parse without validator:
```python
Ensure(load(yaml_snippet)).equals({"a": {"x": "9", "y": "8"}, "b": "2", "c": "3"})
```
Parse with any validator - equivalent:
```python
Ensure(load(yaml_snippet, Any())).equals({"a": {"x": "9", "y": "8"}, "b": "2", "c": "3"})
```
Fix higher levels of schema:
```python
Ensure(load(yaml_snippet, MapPattern(Str(), Any()))).equals({"a": {"x": "9", "y": "8"}, "b": "2", "c": "3"})
```
!!! note "Executable specification"
Documentation automatically generated from
<a href="https://github.com/crdoconnor/strictyaml/blob/master/hitch/story/non-schema-validation.story">non-schema-validation.story
storytests.
|