Heuristic:APIJSON APIJSON Global Keyword Extraction
| Knowledge Sources | |
|---|---|
| Domains | Request_Parsing, Optimization |
| Last Updated | 2026-10-11 00:00 GMT |
Overview
Pattern for extracting @-prefixed global keywords (e.g., @database, @schema, @role, @method) from request objects before recursive parsing, so they propagate to child tables without redundant traversal.
Description
APIJSON uses a convention where keys starting with @ are "global keywords" that control cross-cutting behavior for the entire request or for a specific table's scope. Examples include @database (target database), @schema (schema namespace), @role (access role), @method (HTTP method override), @column (column projection), and @combine (WHERE clause combination logic).
The AbstractParser.parseResponse() method extracts these @-prefixed keys from the top-level request object before descending into recursive object parsing. This ensures that global configuration is resolved once at the root level and inherited by child table parsers, rather than re-parsing the same keys at every nesting level.
Key @-prefixed keywords are defined as constants in JSONMap: KEY_DATABASE, KEY_SCHEMA, KEY_ROLE, KEY_COLUMN, KEY_COMBINE, KEY_METHOD, etc. During parsing, the AbstractObjectParser checks for these keywords in its onParse() method and applies them as configuration rather than treating them as data fields.
Usage
Use this heuristic when:
- Parsing incoming JSON requests that contain @-prefixed control keys
- Need to propagate database, schema, or role settings from parent to child tables
- Implementing custom global keywords that should be extracted before recursive descent
The Insight (Rule of Thumb)
- Action: Extract all keys starting with @ from the request object at the parseResponse() level, before recursive onObjectParse() calls.
- Value: Keys are matched against the JSONMap constant set (KEY_DATABASE, KEY_SCHEMA, KEY_ROLE, etc.) and stored in keyObjectAttributesMap.
- Trade-off: A fixed set of @ keywords is supported; adding new ones requires updating the constant set and the extraction logic.
- Compatibility: Unknown @-prefixed keys are ignored (not treated as errors), allowing forward-compatible extensions.
Reasoning
Extracting global keywords at the top level avoids redundant work: without this, each recursive call to AbstractObjectParser would need to re-scan its key set for @-prefixed entries. By resolving them once and storing them in keyObjectAttributesMap, the parser passes configuration down via setMethod(), setDatabase(), setSchema(), etc., so child parsers inherit the parent's settings without re-extraction.
This also prevents ambiguity: if @database appeared at both root and child level, the child-level value should override. The extraction pattern resolves this by letting the child's @database take precedence during its own onParse() pass.
Code Evidence
Global keyword constants in `JSONMap.java` (excerpt):
public static String KEY_DATABASE = "@database";
public static String KEY_SCHEMA = "@schema";
public static String KEY_ROLE = "@role";
public static String KEY_COLUMN = "@column";
public static String KEY_COMBINE = "@combine";
Attribute map storage in `AbstractParser.java:46`:
protected Map<Object, Map<String, Object>> keyObjectAttributesMap = new HashMap<>();