Request a demo

BigQuery · JSON function

BigQuery JSON_TYPE

JSON_TYPE(json) returns the type of a JSON value as a string: object, array, string, number, boolean or null. Use it to profile inconsistent payloads, tell a JSON null from a missing key, and pick the right conversion for each row.

GoogleSQL for BigQuery · Checked against the official reference in November 2026

JSON_TYPE looks at the outermost level of a JSON value and names its type. It accepts only the JSON type: for JSON text in a STRING, wrap it in PARSE_JSON first, otherwise the call fails with No matching signature for function JSON_TYPE.

It cleanly separates three cases that look alike elsewhere: a key holding a JSON null returns 'null', a missing key returns SQL NULL (because dot access returns SQL NULL for it), and a real value returns its type. That makes it useful for profiling: group a field by JSON_TYPE to see how many rows send numbers, strings or nothing at all.

Use the type to choose a converter, for example FLOAT64(x) for numbers and SAFE_CAST(STRING(x) AS FLOAT64) for numeric strings. The lax converters, such as LAX_FLOAT64, do this coercion for you and return NULL when a value can't be converted.

Syntax

JSON_TYPE(json_expr)

Arguments and return value

ArgumentDescription
json_exprA value of type JSON, such as a JSON column or a field reached with dot access.

Returns: STRING: object, array, string, number, boolean or null. SQL NULL for SQL NULL input.

Examples

Every JSON type

SELECT
  JSON_TYPE(JSON '{"id": 1}') AS object_type,
  JSON_TYPE(JSON '[1, 2]') AS array_type,
  JSON_TYPE(JSON '"A-100"') AS string_type,
  JSON_TYPE(JSON '59.9') AS number_type,
  JSON_TYPE(JSON 'true') AS boolean_type,
  JSON_TYPE(JSON 'null') AS null_type;
Result
object_typearray_typestring_typenumber_typeboolean_typenull_type
objectarraystringnumberbooleannull

Profile a field across rows

The empty object has no amount key, so dot access and JSON_TYPE both return SQL NULL. The explicit JSON null is reported as 'null'.

WITH events AS (
  SELECT JSON '{"amount": 10}' AS payload UNION ALL
  SELECT JSON '{"amount": 12.5}' UNION ALL
  SELECT JSON '{"amount": "10.50"}' UNION ALL
  SELECT JSON '{"amount": null}' UNION ALL
  SELECT JSON '{}'
)
SELECT JSON_TYPE(payload.amount) AS amount_type, COUNT(*) AS events
FROM events
GROUP BY amount_type
ORDER BY amount_type;
Result
amount_typeevents
NULL1
null1
number2
string1

Convert each row according to its type

WITH events AS (
  SELECT 1 AS id, JSON '{"amount": 10}' AS payload UNION ALL
  SELECT 2, JSON '{"amount": "10.50"}' UNION ALL
  SELECT 3, JSON '{"amount": "n/a"}'
)
SELECT
  id,
  CASE JSON_TYPE(payload.amount)
    WHEN 'number' THEN FLOAT64(payload.amount)
    WHEN 'string' THEN SAFE_CAST(STRING(payload.amount) AS FLOAT64)
  END AS amount
FROM events
ORDER BY id;
Result
idamount
110.0
210.5
3NULL

Common mistakes

  • Passing a STRING. JSON_TYPE accepts only JSON; use JSON_TYPE(SAFE.PARSE_JSON(body)) for text that may be invalid.
  • Expecting integer or float. Every JSON number reports number, so 10 and 12.5 look the same.
  • Treating 'null' and SQL NULL as the same thing. 'null' means the key exists with a JSON null; SQL NULL means the key is missing or the input itself is NULL.

FAQ

How do I check if a JSON field is null or missing in BigQuery?

JSON_TYPE(payload.field) = 'null' finds explicit JSON nulls. payload.field IS NULL finds missing keys, because dot access returns SQL NULL for them and a JSON null is not SQL NULL.

How do I find JSON fields with mixed types?

Group by the type: SELECT JSON_TYPE(payload.amount) AS t, COUNT(*) FROM events GROUP BY t. More than one non-NULL group means producers disagree on the type.

Does JSON_TYPE work on STRING columns?

No. Parse the text first: JSON_TYPE(SAFE.PARSE_JSON(body)).

Errors you may hit

More JSON functions

All BigQuery JSON functions · All functions · BigQuery error messages

Observability for every BigQuery table, in about 15 minutes

Masthead detects freshness, volume and schema anomalies, monitors pipeline errors and maps column-level lineage across all your projects, from logs and metadata only.