schema_of_json function (Databricks SQL)

Returns the schema of a JSON string in DDL format.

Syntax

schema_of_json(json [, options] )

Arguments

  • json: A STRING literal with JSON.

  • options: An optional MAP literals with keys and values being STRING.

Returns

A STRING holding a definition of an array of structs with n fields of strings where the column names are derived from the JSON keys. The field values hold the derived formatted SQL types. For details on options, see from_json function (Databricks SQL).

Examples

> SELECT schema_of_json('[{"col":0}]');
 ARRAY<STRUCT<`col`: BIGINT>>
> SELECT schema_of_json('[{"col":01}]', map('allowNumericLeadingZeros', 'true'));
 ARRAY<STRUCT<`col`: BIGINT>>