unescapeJson

Converts a stringified JSON element to a Record, Array or simple field (e.g. String), using the UTF-8 character set. For example, given a schema such as:


{
  "type": "record",
  "name": "events",
  "fields": [{
    "name": "person",
    "type": "record",
    "fields": [
      { "name": "name", "type": "string" },
      { "name": "age", "type": "int" }
    ]
  }]
}

and a record such as:


{
  "json_str": "{\"person\":{\"name\":\"John\",\"age\":30}}"
}

The following record path expression would populate the record with unescaped JSON fields:

RecordPath

Return value

unescapeJson(/json_str)

{"person": {"name": "John", "age": 30}}"

Given a record such as:


{
  "json_str": "\"John\""
}

The following record path expression would return:

RecordPath

Return value

unescapeJson(/json_str)

"John"

Note that the target schema must be pre-defined if the unescaped JSON is to be set in a Record's fields - Infer Schema will not currently do this automatically.