Skip to content

Nested objects

Real test data is rarely flat. A User has an address. An Order has a list of LineItems. A SAP BusinessPartner has zero or more BPAddress rows.

DataMaker handles this with a template field type: a field whose value is itself generated from another template.

Single nested object

Build the inner template first (e.g. Address with street, postcode, city, country). Then in the outer template (User), add a field of type template and pick Address:

{
"name": "address",
"type": "template",
"options": { "template_id": "tmpl_address" }
}

A generated row looks like:

{
"first_name": "Lukas",
"email": "lukas@example.de",
"address": {
"street": "Bahnhofstrasse 12",
"postcode": "10115",
"city": "Berlin",
"country": "DE"
}
}

Array of nested objects

Set array: true and a count (or a count range) to emit a list:

{
"name": "line_items",
"type": "template",
"options": {
"template_id": "tmpl_line_item",
"array": true,
"count": { "min": 1, "max": 5 }
}
}

Each Order row gets between 1 and 5 line items, generated from the LineItem template independently per row.

Cross-field references

A common pattern: the order’s total should equal the sum of its line-item totals. Use a derived field at the parent level:

{
"name": "total",
"type": "derived",
"options": { "expression": "sum(line_items[*].amount)" }
}

The derived expression runs after nested fields are generated, so it has access to the populated array.

For more complex cross-template logic (e.g. “the order’s customer_id must match an existing customer row from a previous step”) use a scenario instead — they run multi-step Python and can pass IDs between generations.

Recursion

Templates can reference themselves. Use the max_depth option to prevent infinite recursion:

{
"name": "replies",
"type": "template",
"options": {
"template_id": "tmpl_comment",
"array": true,
"count": { "min": 0, "max": 3 },
"max_depth": 3
}
}

Useful for threaded comments, org charts, and category trees.

Inline templates

For one-off nested shapes you don’t need elsewhere, define an inline template instead of creating a separate one. In the field editor, pick template and click Inline → Add fields to define the inner schema in place.

Inline templates are lighter weight but can’t be reused; if you find yourself duplicating an inline shape across two parents, promote it to a real template.