reusing json template with variable number of fields (parentId or no parentId)

Hi all, I want to start reusing my json payload templates more so I don’t have so many of them. Problem is I don’t know how to deal with variable number of fields in a similar json template.
For example: in a tenant hierarchy, the first time I create a tenant it has no parent and goes to top of hierarchy. The second…nth time I run through the “createTenant” script the first tenant becomes the parent with parentId in the payload creating the relationship between top and second level of hierarchy.

TopLevelTenant.json:

{
“tenantDescription”: “${tenantDescription}”,
“displayName”: “${tenantDisplayName}”,
“email”: “${tenantName}@doe.com”,
“url”: “https://${tenantName}.com”,
“tenantName”: “${tenantName}”
}

SecondLevelTenant.json:
{
“tenantDescription”: “${tenantDescription}”,
“displayName”: “${tenantDisplayName}”,
“email”: “${tenantName}@doe.com”,
“url”: “https://${tenantName}.com”,
“tenantName”: “${tenantName}”
“parentId”: “${parentId}”
}

Can you give me a hint on how to make something like this more reusable and put both in one json template?

Hi all, NM…I just noticed that gatling supports Pebble templating. I’ll give that a shot.

That, or you can write your own function, similar to StringBody(session => “someString”), where you would use the Session API to fetch data and String interpolation to build the output String.