This Extension is currently limited to the parent and child levels.

Adding and Configuring the Extension

1. Navigate to the Extensions tab and add the Flatten JSON Objects Extension, located under the Advanced tab.


2. Enter a descriptive title.

3. Set the scope for when to flatten the object. You can choose from,

    • Pre-loader
    • DOM-Ready
    • A specific Tag
    • All-Tags

4. Enter the name of the object that you wish to flatten.

5. Enter the name of the new object that the results will be pushed to.

    • Objects such as parent -> child will flatten as parent.child
    • Array objects such as parent -> array -> [obj1,objN] will flatten as parent.array0.obj1key and parent.arrayN.objNkey
    • For arrays, an additional parent.array.array-size value will be set automatically

All-Tags Scope and Execution

If you scope this Extension to All-Tags, you can also choose when to ‘execute' it.

    • Before any Load Rules are evaluated.
    • After any Load Rules are evaluated (Default).
    • After all the Tags have loaded.


Note: The ‘Execution’ dropdown feature requires utag.js version 4.38 or higher; older versions may cause Extension to run more than once.

Usage Example

Here is an example of a JSON object including a parent -> child relationship and an array:


var person_object = {
    "firstName" : "John",
    "lastName" : "Doe",
    "age" : 25,
    "address" :
    "streetAddress" : "1234 Main St",
    "city" : "Los Angeles",
    "state" : "CA",
    "postalCode" : "90010"
    "phoneNumber" :
      "type" : "home",
      "number" : "310-555-1234"
      "type" : "fax",
      "number" : "310-555-5678"

When flattened the object becomes:

var person_flatobject = {
    "" : "Los Angeles",
    "address.postalCode" : "90010"
    "address.state" : "CA",
    "address.streetAddress": "1234 Main St",
    "age" : 25,
    "firstName" : "John",
    "lastName" : "Doe",
    "phoneNumber.array-size" : 2
    "phoneNumber0.number" : "310-555-1234"
    "phoneNumber0.type"  : "home",
    "phoneNumber1.number" : "310-555-5678"
    "phoneNumber1.type"  : "fax"

Notice that the object is now in alphabetical order.

If data in the new object needs to be referenced in the Data Sources tab, use the notation as stated in person_flatobject. For example, you can access the 'state' data in the address as 'person_flatobject.address.state'. Select 'Data Object' as the type for a Data Source from a flattened JSON object.


Note: Avoid flattening objects that are more than three levels deep with this Extension. If you need to flatten a more complex object, please contact your Account Manager to develop a custom solution.