jsonToColumns

Split JSON into multiple columns

Split a JSON (column) object into multiple fields, where the new field names consist of the input field name followed by underscore (_) followed by the JSON field ID.

Operator Usage in Easy Mode

  1. Click + on the parent node.
  2. Enter JSON to Columns operator in the search field and select the operator from the Results to open the operator form.
  3. In the Input Table drop-down, enter or select the table containing the data to run this operator on.
  4. In the JSON Field drop-down, enter or select the column that splits the JSON objects into multiple columns.
  5. In the Defaults Field, click Add More to add a string of default field names.
  6. Click Run to view the result.
  7. Click Save to add the operator to the playbook.
  8. Click Cancel to discard the operator form.

Usage Details

jsonToColumns(table, "jsonField")

-- with default fields
jsonToColumns(table, "jsonField", "a", "test_1")

Input:

table: Name of the input table.
"jsonField": Column (field) name that contains a JSON object (quotes are required).
"defaultFields": A comma-separated string of default field names. Only these fields that are mentioned here will be parsed and converted to columns. If a field does not exist in the JSON object, this operator will create the column and insert nulls.

Output:
A JSON object that is split into multiple columns. Each column is in the form jsonField__id, where jsonField is the input field and id is the JSON ID.

Example

Input
table = github_logs

id jsonField
id{"a":{"b":2,"u":1},"e":3}
id{"a":{"b":4,"v":9},"c":5,"d":7}
jsonToColumns(table, "jsonfield")

Output

id jsonField jsonField__a jsonField__c jsonField__d jsonField__e
id{"a":{"b":2,"u":1},"e":3}{"b":2,"u":1}3
id{"a":{"b":4,"v":9},"c":5,"d":7}{"b":4,"v":9}57

Another Example With Default Fields

jsonToColumns(table, "jsonField", "a", "test_1")

Output

id jsonField jsonField__a jsonField__test_1
id{"a":{"b":2,"u":1},"e":3}{"b":2,"u":1}null
id{"a":{"b":4,"v":9},"c":5,"d":7}{"b":4,"v":9}null

Note: This operator is not recursive. It splits only the first layer. In the example, "b" and "u" or "b" and "v" are subfields of the "a" field, so they are not split into multiple columns.


Did this page help you?