Transformers
Exchange format (also named media):
- json
- yaml - partial support
- xml - partial support
JSON
Generate JSON
var data: aDataDocument
var txt: Text
new(data)
data.Map('keyA').SetCString('valueA')
data.Map('keyB').Map('keyB1').SetInt(42)
data.Map('keyB').Map('keyB2').SetNum(42.42)
data.SetIndent(true)
; Stringify in JSON
if Doc.JSON.StringifyText(data, text)
endIf
write(txt)
txt:=''
Parse JSON
procedure myProcedure
uses aDataDocument, Doc, aStringFormat
var number : Int4
var data : aDataDocument
var myText : Text
var result : aDataValue
var error : aDataValue
new(data)
Write(myText, '{"result": [{"id": 0}, {"id": 1, "count":42}]}}')
if Doc.JSON.ParseText(data, myText)
if data.IsDefined
result = data.FindAtPath('result/1/count')
Write(result.ToCString)
;displays 42
endIf
else
error = data.GetError
myText := ''
if Doc.JSON.StringifyText(error, myText)
Write(myText)
endIf
endIf
endProc
YAML
Generate YAML
var data: aDataDocument
var txt: Text
new(data)
data.Map('keyA').SetCString('valueA')
data.Map('keyB').Map('keyB1').SetInt(42)
data.Map('keyB').Map('keyB2').SetNum(42.42)
data.SetIndent(true)
; Stringify in YAML
if Doc.YAML.StringifyText(data, text)
endIf
write(txt)
txt:=''
Parse YAML
warning
Not supported yet
XML
Generate XML
var data: aDataDocument
var txt: Text
new(data)
data.Map('keyA').SetCString('valueA')
data.Map('keyB').Map('keyB1').SetInt(42)
data.Map('keyB').Map('keyB2').SetNum(42.42)
data.SetIndent(true)
; Stringify in XML
if Doc.XML.StringifyText(data, text)
endIf
write(txt)
txt:=''
Parse XML
warning
Not supported yet