File: merge-yaml-documents.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 (60 lines) | stat: -rw-r--r-- 832 bytes parent folder | download
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
---
title: Merge YAML documents
---


Loaded YAML can be combined and dumped with the comments intact.




```python
from strictyaml import Map, MapPattern, Str, Seq, Int, load

schema_1 = Map({
    "a": Str(),
    "b": Map({"x": Int(), "y": Int()}),
    "c": Seq(MapPattern(Str(), Str())),
})

schema_2 = Map({"x": Int(), "y": Int()})

yaml_1 = load(yaml_snippet_1, schema_1)
yaml_2 = load(yaml_snippet_2, schema_2)

yaml_1['b'] = yaml_2

```



```python
print(yaml_1.as_yaml())
```

```yaml
# Some comment

a: รข # value comment

# Another comment
b:
  x: 8

# y is now 9
  y: 9
c:
- a: 1
- b: 2
```






!!! note "Executable specification"

    Documentation automatically generated from 
    <a href="https://github.com/crdoconnor/strictyaml/blob/master/hitch/story/merge-documents.story">merge-documents.story
    storytests.