Flatten Struct
Description
Converts each property from a Struct into a top-level field. Generates field names by concatenating the parent key name with the child key name using _ delimiter (eg. parent_child or parent_child_nestedChild).
Parameters
- Mode: Specify the behavior mode for flattening Structs.
- Recursive (default): Loop through nested Structs and unnest each property all the way up. If no Struct is selected, the entire schema is flattened from root. If a Struct is selected, all nested Structs under that path are flattened recursively.
- Selective: Flatten only the direct children of the selected Struct one level up into its parent scope. Nested Structs under the selected Struct are preserved as-is.
- Struct: The Struct to flatten. Accepts a dot-separated path — use
structNamefor a top-level Struct (e.g.home) orparent1.parent2.structNamefor a nested Struct (e.g.home.address).- Required when Mode is Selective.
- Optional when Mode is Recursive. If omitted, the transformation applies to the entire schema.
Input Requirements
- At least one field should be a Struct type in order to perform the transformation.
Expected Output
- Moves each field out of the target Struct into its parent scope using the naming convention
parent_child. - In Recursive mode, all nested Structs under the target are flattened and removed from the schema.
- In Selective mode, only the direct children of the target Struct are lifted; nested Structs under the target are preserved.
Examples
Example 1: Basic Struct
// Input
// Mode = "Recursive"
{
"orderId": 123,
"customer": {
"id": 500,
"name": "Alice",
"home_location": "Dallas"
}
}
// Output
{
"orderId": 123,
"customer_id": 500,
"customer_name": "Alice",
"customer_home_location": "Dallas"
}
Example 2: Struct with Nested Properties
// Input
// Mode = "Recursive"
{
"orderId": 123,
"customer": {
"id": 500,
"name": {
"first": "Alice",
"last": "Jones"
}
}
}
// Output
{
"orderId": 123,
"customer_id": 500,
"customer_name_first": "Alice",
"customer_name_last": "Jones"
}
Example 3: Complex Structure
// Input
// Mode = "Recursive"
{
"customerId": "123abc",
"account": {
"accountId": 999999,
"preferences": {
"emailNotification": true
}
},
"deliveryAddress": null,
"orders": [
{
"orderId": 77777,
"orderDetails": {
"isGift": true
}
},
{
"orderId": 444444,
"orderDetails": {
"isGift": false
}
}
]
}
// Output
{
"customerId": "123abc",
"account_accountId": 999999,
"account_preferences_emailNotification": true,
"deliveryAddress": null,
"orders_orderId": [
77777,
444444
],
"orders_orderDetails_isGift": [
true,
false
]
}
Example 4: Selective mode with a top-level Struct
In Selective mode, only the direct children of the target Struct are lifted one level up. Nested Structs under the target (address) are preserved, and Structs outside the target (job) are untouched.
// Mode = "Selective", Struct = "home"
// Input
{
"name": "andy",
"home": {
"city": "New York",
"state": "NY",
"address": {
"street": "Bedford Ave",
"number": 12
}
},
"job": {
"company": "onehouse",
"role": "pm"
}
}
// Output
{
"name": "andy",
"home_city": "New York",
"home_state": "NY",
"home_address": {
"street": "Bedford Ave",
"number": 12
},
"job": {
"company": "onehouse",
"role": "pm"
}
}
Example 5: Selective mode with a nested Struct path
A dot-separated path targets a Struct nested inside another Struct. Its direct children are lifted into its parent; siblings at every level are untouched.
// Mode = "Selective", Struct = "home.address"
// Input
{
"name": "andy",
"home": {
"city": "New York",
"state": "NY",
"address": {
"street": "Bedford Ave",
"number": 12
}
}
}
// Output
{
"name": "andy",
"home": {
"city": "New York",
"state": "NY",
"address_street": "Bedford Ave",
"address_number": 12
}
}