Skip to content

feat: parse BigQuery JSON string literals as implicit casts - #2488

Merged
manticore-projects merged 1 commit into
JSQLParser:manticorefrom
starlake-ai:feat/bigquery-json-literal
Aug 19, 2026
Merged

feat: parse BigQuery JSON string literals as implicit casts#2488
manticore-projects merged 1 commit into
JSQLParser:manticorefrom
starlake-ai:feat/bigquery-json-literal

Conversation

@hayssams

Copy link
Copy Markdown
Contributor

Problem

BigQuery-style JSON string literals fail to parse on the manticore branch:

SELECT BOOL(JSON 'true') AS vacancy
SELECT SAFE.FLOAT64(JSON '9.8') AS result
SELECT JSON_VALUE(JSON '{"name": "Jakob"}', '$.name') AS name

all throw ParseException: Encountered: <S_CHAR_LITERAL> at the literal after JSON. These parsed fine before the Pratt-parser rework (e.g. in the 5.4-SNAPSHOT line from late 2025).

Cause

isImplicitCastAhead() only treats DT_ZONE and DATA_TYPE tokens as implicit-cast prefixes. JSON lexes as K_JSON (it is needed as a keyword elsewhere: FORMAT JSON, FOR JSON AUTO, ...), so JSON 'literal' never reaches ImplicitCast(), even though DataType() already accepts K_JSON as a data type. Inside function arguments the parser then consumes JSON as a column and fails on the following string literal.

Fix

Accept K_JSON in isImplicitCastAhead() when it is directly followed by a string literal, which is unambiguous with all keyword uses of JSON:

// BigQuery JSON 'literal' - JSON lexes as K_JSON, but DataType() accepts it
if (k1 == K_JSON) return getToken(2).kind == S_CHAR_LITERAL;

Adds a regression test to CastExpressionTest covering the standalone literal and the function-argument case.

Validated against the JSQLTranspiler test suite (1042 tests), where this fix resolves 24 BigQuery JSON parse failures without affecting any other test.

🤖 Generated with Claude Code

isImplicitCastAhead() only fired for DATA_TYPE and DT_ZONE tokens, but
JSON lexes as K_JSON, so BigQuery literals like JSON '{"a": 1}' failed
to parse even though DataType() accepts K_JSON as a data type. Accept
K_JSON when directly followed by a string literal.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@hayssams

Copy link
Copy Markdown
Contributor Author

@manticore-projects when you have a moment, could you take a look at this one? It restores BigQuery JSON 'literal' parsing on the manticore branch (2-line change in isImplicitCastAhead() plus a regression test). It unblocks the JSQLTranspiler test suite, which is fully green against a local build of this branch with the fix (1050 tests). Thanks!

@manticore-projects

Copy link
Copy Markdown
Contributor

Thank you very much!

@manticore-projects
manticore-projects merged commit 15e58e9 into JSQLParser:manticore Aug 19, 2026
2 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants