Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Apache Druid Json Completion Engine

From Leeroopedia


Knowledge Sources
Domains Web_Console, Editor_Autocomplete
Last Updated 2026-02-10 10:00 GMT

Overview

Provides a rule-based JSON autocompletion engine for context-aware suggestions in JSON editors.

Description

The JSON Completion Engine module defines interfaces for completion rules and items, and exposes a function to resolve completions based on the current cursor path within a JSON document. Each rule specifies a path pattern (string or regex), an optional condition function evaluated against the current object context, and a list of completion items. The path system converts array indices to bracket notation (e.g., `$.aggregations[].type`) for pattern matching.

Usage

Used in the web console's JSON spec editors (e.g., ingestion spec editor) to provide intelligent autocompletion suggestions when editing Druid configuration JSON documents.

Code Reference

Source Location

Signature

export interface JsonCompletionRule {
  path: string | RegExp;
  isObject?: boolean;
  condition?: (currentObject: any) => boolean;
  completions: JsonCompletionItem[];
}

export interface JsonCompletionItem {
  value: string;
  documentation?: string;
}

export function getCompletionsForPath(
  rules: readonly JsonCompletionRule[],
  path: string[],
  isKey: boolean,
  currentObject: any,
): JsonCompletionItem[];

Import

import { getCompletionsForPath, JsonCompletionRule, JsonCompletionItem } from './utils/json-completion';

I/O Contract

Inputs

Name Type Required Description
rules readonly JsonCompletionRule[] Yes Array of completion rules defining paths and their available completions
path string[] Yes The current cursor path as an array of JSON keys (e.g., ['aggregations', '0', 'type'])
isKey boolean Yes Whether the cursor is at a key position (true) or value position (false)
currentObject any Yes The current JSON object context for evaluating rule conditions

Outputs

Name Type Description
(return) JsonCompletionItem[] Array of matching completion items with value and optional documentation

Usage Examples

Define rules and get completions

import { getCompletionsForPath, JsonCompletionRule } from './utils/json-completion';

const rules: JsonCompletionRule[] = [
  {
    path: '$.aggregations.[].type',
    completions: [
      { value: 'count', documentation: 'Counts the number of rows' },
      { value: 'longSum', documentation: 'Sums a long column' },
    ],
  },
];

const items = getCompletionsForPath(
  rules,
  ['aggregations', '0', 'type'],
  false,
  { type: '' },
);
// Returns: [{ value: 'count', ... }, { value: 'longSum', ... }]

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment