JSONC Merger

A Go tool that merges multiple JSONC files into a single JSONC file. The first file is the base and each subsequent file overrides it, cascading style.

Requirements

  • Go 1.26 or newer (only for compilation. dist/ directory contains binaries).

  • go-task (optional, only for the tasks below).

Usage

From tools/jsonc/src:

go run . --output out.jsonc base.jsonc override1.jsonc override2.jsonc

-output and at least one input file are required. The first input is the base file. Each following file is deep-merged over the previous one, so later files win on conflicts.

Merge semantics

  • Nested objects merge recursively.

  • Arrays and scalar values are replaced wholesale by later files.

  • JSONC comments (// and /* */) and trailing commas are allowed in the inputs and stripped during parsing. The output is plain JSON (which is valid JSONC) with 2-space indentation.

Example

Base:

{
  "colors": { "bg": "red", "accent": "blue" },
  "sizes": [1, 2],
  "name": "base"
}

Override:

{
  "colors": { "accent": "green", "fg": "white" },
  "sizes": [9]
}

Result:

{
  "colors": { "accent": "green", "bg": "red", "fg": "white" },
  "sizes": [9],
  "name": "base"
}

colors merged recursively, sizes was replaced, and keys only present in the base (name) are preserved.

Tasks

From the repository root:

  • task jsonc.build (jb): build the tools/jsonc binary.

  • task jsonc (j): merge lib/common/config/config.jsonc (base) with lib/xcode/config/config.jsonc (overrides) into build/xcode/config.jsonc.

From tools/jsonc/src:

  • task build (b): cross-compile binaries into ../dist/ for macOS (amd64/arm64), Linux (amd64) and Windows (amd64).

  • task test (t): run the test suite.

Release binaries

dist/ contains prebuilt binaries for each platform, named jsonc-<os>-<arch> (Windows uses .exe).