Converting YAML to XML, JSON, or CSV involves transforming data from YAML's human-readable, indentation-based structure into other common data formats. Let's break down each conversion:
1. YAML to XML:
YAML:
yaml
students:
- name: John Doe
age: 22
grade: A
- name: Jane Smith
age: 21
grade: B+
XML:
xml
<students>
<student>
<name>John Doe</name>
<age>22</age>
<grade>A</grade>
</student>
<student>
<name>Jane Smith</name>
<age>21</age>
<grade>B+</grade>
</student>
</students>
2. YAML to JSON:
JSON:
json
{
"students": [
{
"name": "John Doe",
"age": 22,
"grade": "A"
},
{
"name": "Jane Smith",
"age": 21,
"grade": "B+"
}
]
}
3. YAML to CSV:
CSV:
csv
name,age,grade
John Doe,22,A
Jane Smith,21,B+
How to Convert:
With Python: Libraries like pyyaml, json, xml.etree.ElementTree, and csv make this pretty straightforward.
Online Tools: There are plenty of YAML converters online for quick transformations.
Command Line: Tools like yq (YAML processor) can help convert between YAML, JSON, and XML.