Implementation:Apache Druid HjsonCompletions
| Knowledge Sources | |
|---|---|
| Domains | Web_Console, Editor_Autocompletion |
| Last Updated | 2026-02-10 10:00 GMT |
Overview
HjsonCompletions is a module that provides context-aware autocompletion for HJSON editing in the Ace Editor, generating completions based on the current JSON path and editing context.
Description
The module's main function, getHjsonCompletions, analyzes the text before the cursor to determine the current position within the JSON structure (path, current key, whether editing a key or value, and the surrounding object). It then uses JsonCompletionRule definitions to look up available completions for that path, filters them based on context (excluding already-present keys when editing a key, removing boolean/null literals when inside quotes for value editing), and converts them to the Ace Completion format with optional documentation HTML popups.
Usage
Used by the JsonInput component to provide intelligent autocompletion when editing ingestion specs, supervisor specs, compaction configurations, and other HJSON/JSON configuration inputs in the Druid web console.
Code Reference
Source Location
- Repository: Apache Druid
- File: web-console/src/ace-completions/hjson-completions.ts
- Lines: 1-133
Signature
export interface GetHjsonCompletionsOptions {
jsonCompletions: JsonCompletionRule[];
textBefore: string;
charBeforePrefix: string;
prefix: string;
}
export function getHjsonCompletions(options: GetHjsonCompletionsOptions): Ace.Completion[];
Import
import { getHjsonCompletions } from './ace-completions/hjson-completions';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| jsonCompletions | JsonCompletionRule[] | Yes | Array of completion rule definitions describing available keys and values for each JSON path |
| textBefore | string | Yes | The full text content before the current cursor position in the editor |
| charBeforePrefix | string | Yes | The single character immediately before the autocompletion prefix (e.g., '"' or ':') |
| prefix | string | Yes | The current word being typed that triggered autocompletion |
Outputs
| Name | Type | Description |
|---|---|---|
| completions | Ace.Completion[] | An array of Ace Editor completion objects with name, value, score, meta, and optional docHTML |
Usage Examples
Providing completions to an Ace Editor
const completions = getHjsonCompletions({
jsonCompletions: ingestionSpecCompletionRules,
textBefore: allTextBeforeCursor,
charBeforePrefix: '"',
prefix: 'type',
});
// Returns completions like: [{ name: 'type', value: 'type', score: 5, meta: 'property' }]