
A fluent data builder for json and xml
FluentDataBuilder has some NuGet-Libraries to generate output:
install the nuget FluentDataBuilder.Json and follow the general DataBuilder steps. the following code is a sample for the initialization with System.Text.Json.
IDataBuilder builder = new DataBuilder();
...
JsonDocument jsonResult = builder.Build();
install the nuget FluentDataBuilder.NewtonsoftJson and follow the general DataBuilder steps. the following code is a sample for the initialization with Newtonsoft.Json.
IDataBuilder builder = new DataBuilder();
...
JObject jsonResult = builder.Build();
With this package you can store the DataBuilder instance directly as an IConfiguration instance.
install the nuget FluentDataBuilder.Microsoft.Extensions.Configuration and follow the general DataBuilder steps. the following code is a sample for the initialization with Newtonsoft.Json.
IDataBuilder builder = new DataBuilder();
...
IConfiguration configuration = builder.ToConfiguration();
install the nuget FluentDataBuilder.Xml and follow the general DataBuilder steps. the following code is a sample for the initialization with System.Xml.
IDataBuilder builder = new DataBuilder();
...
XmlDocument xmlDocument = builder.Build();
install the nuget FluentDataBuilder.Yaml and follow the general DataBuilder steps..
IDataBuilder builder = new DataBuilder();
...
string yamlContent = builder.Build();
First you need to create an instance:
IDataBuilder builder = new DataBuilder();
Use the Add-Method to add data:
builder.Add("StringProperty", "a value");
builder.Add("NumericProperty", 12345);
builder.Add("BooleanProperty", true);
result (in json):
{
    "StringProperty": "a value",
    "NumericProperty": 12345,
    "BooleanProperty": true
}
builder.Add("ListProperty", new List<string> { "this", "is", "a", "test" });
builder.Add("ArrayProperty", new string[] { "this", "is", "a", "test" });
builder.Add("MixedListProperty", new List<object> { "value", 123, true, 456.78 });
result (in json):
{
    "ListProperty":
    [
        "this",
        "is",
        "a",
        "test"
    ],
    "ArrayProperty":
    [
        "this",
        "is",
        "a",
        "test"
    ],
    "MixedListProperty":
    [
        "value",
        123,
        true,
        456.78
    ]
}
builder.Add("ObjectProperty", new DataBuilder()
    .Add("StringProperty", "another value")
    .Add("NumericProperty", 67890)
    .Add("BooleanProperty", false));
result (in json):
{
    "ObjectProperty":
    {
        "StringProperty": "another value",
        "NumericProperty": 67890,
        "BooleanProperty": false
    }
}