Skip to content

Implement JSON Path parser and related routines#9062

Open
Noremos wants to merge 7 commits into
FirebirdSQL:masterfrom
Noremos:json_path_implementation
Open

Implement JSON Path parser and related routines#9062
Noremos wants to merge 7 commits into
FirebirdSQL:masterfrom
Noremos:json_path_implementation

Conversation

@Noremos

@Noremos Noremos commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Full JSON support introduces a large number of changes, so it was decided to split the work into several smaller PRs to simplify the review process.

Original issue: #5431

The current plan is as follows:

JSON
├─ JSON Path
├─ ├─ JSON Path Parser
├─ ├─ JSON Path Runtime execution
├─ JSON Content
│  ├─ Text Parser
│  ├─ JSON Binary Storage
│  │  ├─ BLOB Random Write
│  ├─ JSON Text Storage
│  ├─ JSON Query Actions (backend for JSON Functions)
├─ Engine Side
│  ├─ JSON Type
│  │  ├─ Logical
│  │  ├─ Physical
│  ├─ JSON_TABLE
│  ├─ JSON ExprNodes
│  ├─ JSON AggNodes
├─ Regression Fixes After Review Feedback

The physical JSON type is the most interesting part of the implementation, but also the most complex from the engine perspective.
As described in the proposal, it is a simple structure that encapsulates either a VARCHAR or a BLOB value:

struct FB_INLINE_BLOB_t {
	ISC_USHORT inlineLength;
	ISC_USHORT flags;
	union
	{
		ISC_QUAD id;
		unsigned char inlineData[1];
	};
};

typedef struct FB_INLINE_BLOB_t FB_JSON_t;

The idea is to use this type as the foundation for storing unlimited data types, such as JSON and spatial data.
However, this approach requires extensive discussion, and given the FB6 release schedule, there will likely not be enough time to include it.
As a fallback, BLOB can be used as the physical storage type. In FB7, it can be converted to FB_INLINE_BLOB_t during backup-restore.

This PR contains the implementation of JSON Path parsing and related routines
See doc/sql.extensions/README.json.md for additional details.


The current implementation aims to remain as close to the SQL standard as possible, with the following changes:

  1. Support negative indexes in array range:
    Standard: [last - 4]
    Proposed extension: [-5]

  2. Extended like_regex syntax
    Standard: <JSON like_regex pattern> ::= <string literal>
    Proposed extension: <JSON like_regex pattern> ::= <string literal> | <JSON path>

  3. Do not use arithmetic operations in the input arguments of like_regex and STARTS WITH.
    Expressions such as $.value + $passing STARTS WITH 'hello' are invalid: arithmetic operations apply only to numeric values, while like_regex and STARTS WITH operate exclusively on strings. Additionally, such constructs confuse the parser

  4. Do not allow path accessors after methods since they return a scalar (except keyvalue())

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.

1 participant