Reading the repo
Reading the repo
Assembly instructions
A YAML Parser for Delphi
Saved setup from 6 h ago
Will it work on macOS?
Compare yours with the README's “Compatibility” list above before installing anything.
Needs Git: xcode-select --install
git clone https://github.com/VSoftTechnologies/VSoft.YAML.git cd VSoft.YAML
uses VSoft.YAML;
var
doc: IYAMLDocument;
yaml: string;
begin
yaml := 'name: John Doe' + sLineBreak +
'age: 30' + sLineBreak +
'city: New York';
doc := TYAML.LoadFromString(yaml);
WriteLn('Name: ', doc.Root.Values['name'].AsString);
WriteLn('Age: ', doc.Root.Values['age'].AsInteger);
end;
var
doc: IYAMLDocument;
person: IYAMLMapping;
begin
doc := TYAML.CreateMapping;
person := doc.Root.AsMapping;
person.AddOrSetValue('name', 'Jane Smith');
person.AddOrSetValue('age', 25);
WriteLn(TYAML.WriteToString(doc));
end;
var
doc: IYAMLDocument;
fruits: IYAMLSequence;
begin
yaml := 'fruits:' + sLineBreak +
' - apple' + sLineBreak +
' - banana' + sLineBreak +
' - orange';
doc := TYAML.LoadFromString(yaml);
fruits := doc.Root.Values['fruits'].AsSequence;
for i := 0 to fruits.Count - 1 do
WriteLn('Fruit: ', fruits.Items[i].AsString);
end;
var
documents: TArray<IYAMLDocument>;
doc1, doc2: IYAMLDocument;
yamlContent: string;
begin
// Create multiple documents
doc1 := TYAML.CreateMapping;
doc1.AsMapping.AddOrSetValue('name', 'Config 1');
doc1.AsMapping.AddOrSetValue('version', 1);
doc2 := TYAML.CreateMapping;
doc2.AsMapping.AddOrSetValue('name', 'Config 2');
doc2.AsMapping.AddOrSetValue('version', 2);
// Write multiple documents
SetLength(documents, 2);
documents[0] := doc1;
documents[1] := doc2;
yamlContent := TYAML.WriteAllToString(documents);
WriteLn('Multi-document YAML:');
WriteLn(yamlContent);
// Load multiple documents
documents := TYAML.LoadAllFromString(yamlContent);
WriteLn('Loaded ', Length(documents), ' documents');
end;
var
doc: IYAMLDocument;
root: IYAMLMapping;
begin
doc := TYAML.CreateMapping;
root := doc.AsMapping;
// Add values with explicit tags
root.AddOrSetValue('port', '8080', '!!int'); // Force integer type
root.AddOrSetValue('name', 'server', '!!str'); // Force string type
root.AddOrSetValue('config', configData, '!app!config'); // Custom tag
WriteLn(TYAML.WriteToString(doc));
end;
var
doc: IYAMLDocument;
person: IYAMLMapping;
jsonOutput: string;
begin
// Create a YAML document
doc := TYAML.CreateMapping;
person := doc.Root.AsMapping;
person.AddOrSetValue('name', 'John Doe');
person.AddOrSetValue('age', 30);
person.AddOrSetValue('city', 'New York');
// Export to compact JSON
doc.Options.PrettyPrint := false;
jsonOutput := TYAML.WriteToJSONString(doc);
WriteLn('Compact JSON: ', jsonOutput);
// Output: {"name":"John Doe","age":30,"city":"New York"}
// Export to pretty-printed JSON
doc.Options.PrettyPrint := true;
doc.Options.IndentSize := 2;
jsonOutput := TYAML.WriteToJSONString(doc);
WriteLn('Pretty JSON:');
WriteLn(jsonOutput);
// Output:
// {
// "name": "John Doe",
// "age": 30,
// "city": "New York"
// }
// Write JSON to file
TYAML.WriteToJSONFile(doc, 'output.json');
end;
var
yamlDoc: IYAMLDocument;
yamlContent: string;
jsonOutput: string;
begin
// Load YAML content
yamlContent := 'employees:' + sLineBreak +
' - name: Alice' + sLineBreak +
' role: Developer' + sLineBreak +
' - name: Bob' + sLineBreak +
' role: Designer';
yamlDoc := TYAML.LoadFromString(yamlContent);
// Convert to JSON with pretty printing
yamlDoc.Options.PrettyPrint := true;
jsonOutput := TYAML.WriteToJSONString(yamlDoc);
WriteLn('YAML to JSON conversion:');
WriteLn(jsonOutput);
// Output:
// {
// "employees": [
// {
// "name": "Alice",
// "role": "Developer"
// },
// {
// "name": "Bob",
// "role": "Designer"
// }
// ]
// }
end;
Numbers are written exactly as they were read or added, in JSON and YAML, rather than going through Int64 or Double. For values that no Delphi type holds, such as a SQL DECIMAL(38,10), add the number from its text with AddOrSetNumber (on a sequence, AddNumber). The text must be a JSON number (-, digits, an optional fraction and an optional exponent), or EConvertError is raised. Like a parsed number, it is an integer unless it has a fraction or an exponent.
var
doc: IYAMLDocument;
row: IYAMLMapping;
price: Currency;
begin
doc := TYAML.CreateMapping;
row := doc.AsMapping;
price := 19.99;
row.AddOrSetValue('id', UInt64(High(UInt64)));
row.AddOrSetCurrencyValue('price', price);
row.AddOrSetNumber('total', '1234567890123456789012345678.9012345678');
row.AddOrSetValue('note', ''); // an empty string
row.AddOrSetNull
…
No reports for macOS yet.
Opens a chat with this manual already filled in, for macOS. It uses your own account; gitmanual sends nothing.