Parses Yaml and JSON documents from string or file. Requires AutoHotkey v2.106+
Full length examples from yaml.org:Most of Yaml 1.2 spec are implemented:How to use:
- Mapping between Sequences is not supported, see Example 2.11.
- Only tags !!str, !!int, !!float, !!binary, !!bool and !!null are supported. !!set results in error and all other tags are ignored.
- Only Yaml documents with 1000 level deepness can be parsed (to increase simply increase Loop 1000 in Load(ByRef txt,Y:=0)
- Other features might be not implemented.
- Yaml uses objects for map and arrays for sequence, however Dump will work for Array, Map and Object.
- Create an Object from Text or File:
YamlObj:=Yaml(TextOrFilePath)- Apply/combine another Yaml document into existing object:
Yaml(TextOrFilePath, YamlObject)- Dump Yaml object back to text, use JSON from 5-th level only:
Yaml(YamlObject, 5)- Dump Yaml object back to text, use JSON only and indent until 5-th level (v1.0.4++):
Yaml(YamlObject, -5)- Yaml(TextOrFilePath) will result in Array of documents (objects), if you have only one document you can retrieve it directly:
YamlObj:=Yaml(TextOrFilePath)[1]
Code: Select all
text:="
(
--- !<tag:clarkevans.com,2002:invoice>
invoice: 34843
date : 2001-01-23
bill-to: &id001
given : Chris
family : Dumars
address:
lines: |
458 Walkman Dr.
Suite #292
city : Royal Oak
state : MI
postal : 48046
ship-to: *id001
product:
- sku : BL394D
quantity : 4
description : Basketball
price : 450.00
- sku : BL4438H
quantity : 1
description : Super Hoop
price : 2392.00
tax : 251.42
total: 4443.52
comments:
Late afternoon is best.
Backup contact is Nancy
Billsmer @ 338-4338.
---
Time: 2001-11-23 15:01:42 -5
User: ed
Warning:
This is an error message
for the log file
---
Time: 2001-11-23 15:02:31 -5
User: ed
Warning:
A slightly different error
message.
---
Date: 2001-11-23 15:03:17 -5
User: ed
Fatal:
Unknown variable "bar"
Stack:
- file: TopClass.py
line: 23
code: |
x = MoreObject("345\n")
- file: MoreClass.py
line: 58
code: |-
foo = bar
)"
y:=Yaml(text) ; Load Yaml documents into objects
MsgBox Yaml(y,5) ; Dump objects back into Yaml