PayloadForge 1.0.0

dotnet add package PayloadForge --version 1.0.0
                    
NuGet\Install-Package PayloadForge -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PayloadForge" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PayloadForge" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="PayloadForge" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PayloadForge --version 1.0.0
                    
#r "nuget: PayloadForge, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package PayloadForge@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PayloadForge&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=PayloadForge&version=1.0.0
                    
Install as a Cake Tool

PayloadForge

PayloadForge helps you generate realistic test payloads from simple templates.

Instead of generating a single random string and wiring the rest of the payload by hand, you define the whole request or message shape once and let PayloadForge fill in the moving parts. That makes it useful for:

  • API request and response testing
  • integration tests
  • contract tests
  • fuzzing light variations of valid payloads
  • generating repeatable sample data for local development
  • building many test cases from one JSON, XML, or YAML template

It is basically "regex in reverse", but applied to complete payload generation.

Why It Helps

Developers rarely need a random string by itself. They usually need a valid payload:

  • a JSON body with a valid id, email, status, and age
  • an XML document with dynamic values in attributes and elements
  • a YAML config or event payload with realistic structure
  • multiple variations of the same payload shape for test coverage

PayloadForge is designed for that workflow. You keep the payload readable, mark the dynamic values with placeholders, and generate as many variations as you need.

Current API

The first version keeps the public API intentionally small:

var forge = new PayloadForgeGenerator();

IReadOnlyList<string> strings = forge.GenerateString("[A-Z]{3}-\\d{4}", 5);
IReadOnlyList<string> jsonPayloads = forge.GenerateJson(jsonTemplate, 10);
IReadOnlyList<string> xmlPayloads = forge.GenerateXml(xmlTemplate, 10);
IReadOnlyList<string> yamlPayloads = forge.GenerateYaml(yamlTemplate, 10);

Each method returns quantity generated payloads.

Quick Example

Here is the kind of template PayloadForge is built for:

{
  "id": "{{regex:[A-Z]{3}-\\d{4}}}",
  "email": "{{faker:internet.email}}",
  "zip": "{{regex:\\d{5}}}",
  "status": "{{oneof:Pending,Active,Suspended}}",
  "age": "{{int:18,90}}",
  "balance": "{{decimal:10.5,99.5,2}}",
  "isActive": "{{bool}}"
}

Possible generated output:

{
  "id": "QXM-4821",
  "email": "alex284@example.com",
  "zip": "58103",
  "status": "Active",
  "age": 34,
  "balance": 48.27,
  "isActive": true
}

The important part is that the result is still valid JSON, with numbers and booleans emitted as numbers and booleans instead of as strings.

Placeholder DSL

Supported placeholders in this first cut:

  • regex:<pattern>
  • oneof:value1,value2,value3
  • int:min,max
  • decimal:min,max[,scale]
  • email
  • faker:internet.email
  • guid
  • bool

Nullable variants are supported for:

  • oneof?
  • int?
  • decimal?
  • bool?

For example:

{
  "age": "{{int?:18,90}}",
  "status": "{{oneof?:Pending,Active,Suspended}}",
  "score": "{{decimal?:0,100,2}}",
  "isActive": "{{bool?}}"
}

When a nullable placeholder resolves to null:

  • JSON emits null
  • YAML emits null
  • XML currently resolves to an empty value

Collection Directives

Variable-length collections are opt-in.

If you do nothing special, arrays and repeated elements keep the exact shape defined in the template.

When you want variable-length generation, use one of these directives:

  • JSON arrays: first item marker like {{array:1,3}}
  • YAML sequences: first item marker like {{array:1,3}}
  • XML repeated elements: payloadforge-repeat="1,3" on the prototype element

You can also use an exact count:

  • {{array:3}}
  • payloadforge-repeat="3"

The directive is optional. If it is not present, PayloadForge keeps the original number of items from the template.

Usage Examples

Generate Strings From Regex

var forge = new PayloadForgeGenerator();
var values = forge.GenerateString("[A-Z]{3}-\\d{4}", 3);

Example output:

ABC-1042
QZT-8891
LMN-5508

This is useful when you just need a valid token, code, id, or field value.

Generate JSON Payloads

var forge = new PayloadForgeGenerator();

var template = """
{
  "id": "{{guid}}",
  "email": "{{faker:internet.email}}",
  "status": "{{oneof:Pending,Active,Suspended}}",
  "age": "{{int:18,90}}",
  "orderTotal": "{{decimal:25,500,2}}"
}
""";

var payloads = forge.GenerateJson(template, 2);

This is useful for API tests where you want many request bodies that all remain structurally valid.

Variable-Length JSON Arrays

JSON arrays can opt into range-based generation by using a directive as the first item and the template item as the second:

{
  "users": [
    "{{array:1,3}}",
    {
      "id": "{{guid}}",
      "email": "{{email}}"
    }
  ]
}

Possible output:

{
  "users": [
    {
      "id": "8d2b35f5-7d4d-4e02-b5f4-9ba0b3378d53",
      "email": "jamie412@example.com"
    },
    {
      "id": "eb39aab4-e44c-4633-aec5-e94209aeed25",
      "email": "alex901@testmail.dev"
    }
  ]
}

If the first array item is not an {{array:...}} directive, the array is treated normally and each template item is kept.

Dynamic JSON Field Names

If you need it, even field names can be generated:

{
  "{{oneof:customerId,accountId}}": "{{regex:[A-Z]{2}-\\d{2}}}",
  "status": "ok"
}

Possible output:

{
  "customerId": "AB-42",
  "status": "ok"
}

Generate XML Payloads

var template = """
<user id="{{regex:[A-Z]{2}-\d{2}}}" active="{{bool}}">
  <status>{{oneof:Pending,Active}}</status>
  <age>{{int:18,90}}</age>
</user>
""";

var payloads = forge.GenerateXml(template, 2);

Possible output:

<user id="XZ-18" active="true"><status>Active</status><age>42</age></user>

This fits nicely when you need realistic XML requests, event payloads, or message bodies for older integrations.

Repeated XML Elements

XML uses a helper attribute on the prototype element:

<users>
  <user payloadforge-repeat="1,3">
    <id>{{guid}}</id>
    <email>{{email}}</email>
  </user>
</users>

Possible output:

<users><user><id>23703d84-e0a9-4677-9054-d8f98c1b2b9f</id><email>casey518@sample.net</email></user><user><id>ef0385a5-c902-4e3c-98d0-f32c900a0531</id><email>riley204@example.com</email></user></users>

The payloadforge-repeat attribute is only a template instruction. It is removed from the emitted XML.

Dynamic XML Element Names

XML element names can be driven by a helper attribute:

<root>
  <node payloadforge-name="{{oneof:customerId,accountId}}">{{regex:[A-Z]{2}-\d{2}}}</node>
</root>

Possible output:

<root><accountId>AB-42</accountId></root>

The payloadforge-name attribute is only a template instruction. It is removed from the emitted XML.

Generate YAML Payloads

var template = """
id: '{{regex:[A-Z]{2}-\d{3}}}'
email: '{{email}}'
status: '{{oneof:Pending,Active}}'
age: '{{int:18,90}}'
balance: '{{decimal:10.5,99.5,2}}'
""";

var payloads = forge.GenerateYaml(template, 2);

Possible output:

id: AB-104
email: taylor582@payloadforge.io
status: Pending
age: 27
balance: 64.31

This is especially handy for config testing, workflow files, and event-driven systems that consume YAML.

Variable-Length YAML Sequences

YAML sequences use the same first-item directive pattern as JSON:

users:
  - '{{array:1,3}}'
  - id: '{{guid}}'
    email: '{{email}}'

Possible output:

users:
- id: 88594b1d-5344-4800-a0ef-fb2f9a2ac241
  email: drew338@payloadforge.io
- id: e8ff6a44-9546-4f5d-81c8-c8ed5d7f62e5
  email: morgan907@example.com

If the directive is not present, the sequence keeps the exact items defined in the template.

Dynamic YAML Keys

YAML keys can also be generated. Because { and } have meaning in YAML, quote the key placeholder in the template:

'{{oneof:customerId,accountId}}': '{{regex:[A-Z]{2}-\d{2}}}'
status: ok

Possible output:

customerId: AB-42
status: ok

Notes

  • JSON object property names can themselves be placeholders.
  • XML element names can be driven from a payloadforge-name="{{...}}" helper attribute.
  • JSON arrays and YAML sequences can optionally use {{array:min,max}} or {{array:count}} as the first item to expand one template item into many generated items.
  • XML elements can optionally use payloadforge-repeat="min,max" or payloadforge-repeat="count" to clone a prototype element.
  • If no collection directive is present, arrays, YAML sequences, and repeated XML elements keep the exact template shape.
  • quantity controls how many top-level payloads are generated, not how many items are added inside a collection unless you use a collection directive.
  • JSON placeholders preserve scalar types when the entire string value is a single placeholder.
  • XML resolves placeholders inside attribute values and element text.
  • YAML uses YamlDotNet to parse and re-emit valid YAML.
  • The regex generator currently supports a practical subset of regex syntax for test-data generation: character classes, ranges, groups, alternation, literals, anchors, escapes, and common quantifiers.

Example Test Scenarios

PayloadForge is a good fit when you want to generate:

  • many valid signup requests with different emails, ages, and status values
  • many order payloads with IDs, totals, and optional state transitions
  • XML partner-integration messages with different element values
  • YAML configs with varied but valid combinations of settings
  • repeated payload variations from a single baseline template

Testing

Run the test suite with:

dotnet test PayloadForge.slnx
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 117 3/25/2026