FLATTEN_JSON

Flattens nested JSON into a new object with a single layer of key/value pairs. Default key separator is a period or full stop (.)

Syntax 

FLATTEN_JSON(object, [separator])

Examples 

Example 1

Input

{
  "contact": {
    "address": [
      {
        "city": "Huntsville",
        "geo": {
          "lat": "2.243232",
          "lon": "1.23123"
        },
        "state": "NC",
        "street": "101 3rd St",
        "type": "home"
      },
      {
        "city": "city",
        "geo": {
          "lat": "2.243232",
          "lon": "1.23123"
        },
        "state": "NC",
        "street": "15 Main St",
        "type": "work"
      }
    ],
    "id": "557",
    "name": "Jane Smith"
  }
}

Formula

FLATTEN_JSON(json)

Output

{
  "contact.address.0.city": "Huntsville",
  "contact.address.0.geo.lat": "2.243232",
  "contact.address.0.geo.lon": "1.23123",
  "contact.address.0.state": "NC",
  "contact.address.0.street": "101 3rd St",
  "contact.address.0.type": "home",
  "contact.address.1.city": "city",
  "contact.address.1.geo.lat": "2.243232",
  "contact.address.1.geo.lon": "1.23123",
  "contact.address.1.state": "NC",
  "contact.address.1.street": "15 Main St",
  "contact.address.1.type": "work",
  "contact.id": "557",
  "contact.name": "Jane Smith"
}
Was this helpful?