Skip to main content

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 (currently the only option): Loop through nested Structs and unnest each property into a top-level field.

Input Requirements

  • At least one field should be a Struct type in order to perform the transformation.

Expected Output

  • Moves each field to a property in the Struct with the naming convention parent_child.
  • Removes all flattened Structs from the schema.

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
]
}