Parse as JSON directive
The PARSE-AS-JSON directive is for parsing a JSON object. The directive can operate on String or JSONObject types. When the directive is applied, the high-level keys of the JSON are appended to the original column name to create new column names.
Syntax
parse-as-json :column [depth]
column
 is the name of the column in the record that is a JSON object.depth
 indicates the depth at which JSON object enumeration terminates.
Usage Notes
The PARSE-AS-JSON directive breaks down complex JSON into simpler understandable and manageable chunks. When first applied on a JSON object, it breaks it down into keys and values. The value could in itself be a JSON object on which you can apply the PARSE-AS-JSON directive again to flatten it out further.
The key names in the event object are appended to the column that is being applied JSON parsing. The column names use dot notation.
Examples
Using this record as an example, in a field body
:
{
"id": 1,
"name": {
"first": "Root",
"last": "Joltie"
},
"age": 22,
"weigth": 184,
"height": 5.8
}
Applying this directive:
parse-as-json :body
results in this record:
Field Name | Field Values | Field Type |
---|---|---|
|
| String |
| 1 | Integer |
|
| JSONObject |
| 22 | Integer |
| 184 | Integer |
| 5.8 | Double |
Applying the same directive, but just on the field body_name
 would result in this record:
Field Name | Field Values | Field Type |
---|---|---|
|
| String |
| 1 | Integer |
|
| JSONObject |
| Root | String |
| Joltie | String |
| 22 | Integer |
| 184 | Integer |
| 5.8 | Double |
Â
Created in 2020 by Google Inc.