Skip to content

Instantly share code, notes, and snippets.

@astrojuanlu
Last active December 18, 2024 09:38
Show Gist options
  • Save astrojuanlu/af35bbbe949b9d9c1ea95224e9778f49 to your computer and use it in GitHub Desktop.
Save astrojuanlu/af35bbbe949b9d9c1ea95224e9778f49 to your computer and use it in GitHub Desktop.
Experiments with YAML and JSON5
document:
key1: "value1"
key2: "value2"
list1:
- "item1"
- "item2"
- dictionary1:
key3: "value3"
key4: "value4"
list2:
- "item3"
- "item4"
list3:
- "item5"
- "item6"
key5: "value5"
document2: 1
document: {
key1: "value1",
key2: "value2",
list1: [
"item1",
"item2",
{
dictionary1: {
key3: "value3",
key4: "value4",
list2: [
"item3",
"item4"
],
list3: [
"item5"
]
}
},
"item6"
],
key5: "value5"
}
document2: 1
{
document: {
key1: "value1",
key2: "value2",
list1: [
"item1",
"item2",
{
dictionary1: {
key3: "value3",
key4: "value4",
list2: [
"item3",
"item4"
],
list3: [
"item5"
]
}
},
"item6"
],
key5: "value5"
},
document2: 1
}
import json5
from ruamel.yaml import YAML
yaml = YAML()
with open("example.yaml") as fh:
content = yaml.load(fh.read())
with open("example_clean.yaml") as fh:
content_clean = yaml.load(fh.read())
with open("example_json5.yaml") as fh:
content_json5_w_yaml = yaml.load(fh.read())
with open("example_json5.yaml") as fh:
content_json5 = json5.load(fh)
assert content == content_clean == content_json5_w_yaml == content_json5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment