Skip to content

JSON output (--json)

The global --json flag switches supported commands from human-oriented stderr/stdout to a stable machine-readable contract on stdout. Use it in CI, scripts, and editor integrations when you need deterministic parsing — not for day-to-day terminal work (see verbosity for human output).

What --json guarantees

RuleBehavior
StdoutOne primary JSON document per invocation (pretty-print optional via --json-pretty)
StderrHuman progress, cache/debug lines, and banners — never mixed into the JSON document
PromptsDisabled on JSON-capable commands; missing required input fails fast with an envelope or usage error
okTop-level success gate — scripts should use exit code and ok (see jq cookbook)
issues[]Stable i18nprune.* codes with optional docHref; warnings do not always imply ok: false
kindCommand id (validate, sync, providers, …) — parse this before assuming data shape
dataCommand-specific payload; additive fields are allowed within the same apiVersion

Commands that do not implement --json ignore the flag (for example help). The supported set is listed below.

Envelope shape

Every JSON-capable command emits the same top-level object:

json
{
  "ok": true,
  "kind": "<command-id>",
  "data": {},
  "issues": [],
  "meta": { "apiVersion": "1", "cwd": "..." }
}

issues[] entries include code, severity, message, and often docHref / docPath for published issue docs.

Version fields

meta.apiVersion (envelope contract)

meta.apiVersion is the CLI JSON envelope contract version, not the npm package version.

  • Current value: "1".
  • Declared in code as RESULT_API_VERSION and emitted on every --json envelope.
  • Bump apiVersion only when the envelope shape or cross-command semantics change (for example removing issues[], renaming ok, or changing global failure rules).
  • Additive changes inside data or new optional issue fields do not require an envelope bump.

npm package version (i18nprune / @i18nprune/core)

The semver on npm (today 0.1.x) tracks package releases. Pre-1.0 semver allows additive CLI/SDK behavior while the envelope stays at apiVersion: "1".

Issue codes

issues[].code values (for example i18nprune.validate.missing_literal_keys) are stable API. Display text and docHref may change; codes are not renamed without a documented breaking release.

Commands with JSON envelopes

kindCommandNotes
configi18nprune configResolved config snapshot
validatei18nprune validateKey observations, missing keys, suggestions
missingi18nprune missingScaffold plan + suggestions
synci18nprune syncMerge/prune summary
generatei18nprune generateProgress + translate outcome
qualityi18nprune qualityDrift / parity findings
reviewi18nprune reviewLocale summaries
cleanupi18nprune cleanupRemovable keys, optional targets[]
languagesi18nprune languagesCatalog listing
providersi18nprune providersTranslation backend discovery (read-only)
doctori18nprune doctorEnvironment + config checks
reporti18nprune report --jsonCLI envelope wrapping data.document
localeslocales list / dynamic / deletePer-subcommand payloads

SDK equivalents live under sdk/operations; CLI envelopes are thin wrappers around the same core results.

Long-running and streaming behavior

  • Progress for generate and similar ops uses structured events internally; the final stdout line(s) still resolve to one envelope (or documented multi-line JSON only where explicitly noted).
  • --quiet / --silent reduce human stderr; they do not remove the JSON document when --json is set.
  • Presentation flags (--no-color, --no-log-prefix, …) affect human lines only — see output.

Command-specific notes

Report: two JSON outputs

  • i18nprune report --format json --out … writes a project report document (kind: "i18nprune.projectReport") to a file.
  • i18nprune report --json emits the CLI envelope (kind: "report") with data.document on stdout.

Providers discovery

i18nprune providers --json returns registered translation backends (id, label, kind, envVars, configSnippets) — no locale writes. Example shape:

json
{
  "ok": true,
  "kind": "providers",
  "data": {
    "providers": [{ "id": "google", "label": "Google Translate", "kind": "public_http", "envVars": [] }],
    "mergePrecedence": "CLI --provider → env I18NPRUNE_TRANSLATE_PROVIDER → config translate.primary → …",
    "configSnippets": { "google": "translate: { primary: 'google', … }" }
  },
  "issues": [],
  "meta": { "apiVersion": "1", "cwd": "/path/to/project" }
}

See providers for human output.