mcpField
C
Compare JSON

Compare JSON

Local
github.com/unitstackDeveloper Tools0Updated 11w ago

About Compare JSON

A command-line tool and MCP server for developers who need to compare JSON strings, values, or files. It reports additions, deletions, type changes, and value changes, with configurable array and case-comparison behavior.

Key features

  1. 01Compare JSON values or files
  2. 02Detect four types of differences
  3. 03Index, LCS, or unordered array comparison
  4. 04Case-insensitive key and value options
  5. 05JSON or table output
  6. 06Save results to a file

Use cases

  1. 01Review changes between JSON files
  2. 02Inspect API or configuration data differences
  3. 03Use JSON comparison from an MCP client

MCP support

It runs as an MCP server over stdio and exposes the compare_json tool, which returns structured differences between JSON inputs.

Configuration

Local server config is the same for every client. Copy it into your client’s MCP config file.

mcp.json · Universal config
{
"mcpServers": {
"compare-json-cli": {
"command": "npx",
"args": [
"-y",
"@compare-json/cli"
]
}
}
}
Run commandnpx -y @compare-json/cli

Local servers need a runtime on your machine (e.g. Node.js 18+). Config file locations differ by client; see your client’s docs.

Packages
npm@compare-json/cli

Tools

1

Saved tool list · updated 3w ago

ParameterTypeRequiredDescription
baseJSONanyNoBase JSON value
baseJSONStringstringNoBase stringified JSON value
baseJSONFilePathstringNoBase JSON file path
contrastJSONanyNoContrast JSON value
contrastJSONStringstringNoContrast stringified JSON value
contrastJSONFilePathstringNoContrast JSON file path
optionsobjectNo
options.arrayCompareMethodenumYesArray comparison methodbyIndex | lcs | unordered
options.keyCaseInsensitivebooleanYesCase insensitive key comparison
options.valueCaseInsensitivebooleanYesCase insensitive value comparison
options.numericStringEqualsNumberbooleanYesTreat numeric strings as numbers

Details

From the project README

@compare-json/cli

A command-line tool and MCP server for comparing JSON files or strings. Built on top of @compare-json/core.

Online Playground

Try it out at https://comparejson.com

Installation

# npm
npm install -g @compare-json/cli

# yarn
yarn global add @compare-json/cli

# pnpm
pnpm add -g @compare-json/cli

CLI

Quick Start
# View help
compare-json --help

# Compare two JSON strings
compare-json '{"a":1}' '{"a":2}'

# Compare two JSON files
compare-json file1.json file2.json

# Output as JSON format
compare-json file1.json file2.json --json-export

# Save output to file
compare-json file1.json file2.json -o output.txt

# Start the MCP server (stdio transport)
compare-json --mcp
Usage
compare-json [base] [contrast] [options]

Each positional argument can be either an inline JSON string or a path to a JSON file. The CLI inspects the value: if it resolves to an existing file, the file content is parsed; otherwise the argument itself is parsed as JSON. If neither base nor contrast is provided (and --mcp is not set), help is printed.

Arguments
ArgumentDescription
[base]Base JSON string or file path
[contrast]Contrast JSON string or file path
Options
OptionAliasDescriptionDefault
--array-compare-method <method>-aArray compare method: byIndex, lcs, unorderedbyIndex
--key-case-insensitive-kCase-insensitive key comparisonfalse
--value-case-insensitive-vCase-insensitive value comparisonfalse
--numeric-string-equals-number–Treat numeric strings as numbersfalse
--json-export-jOutput as JSON formatfalse
--output <file>-oWrite output to a file instead of stdout–
--mcp–Run as an MCP server via stdiofalse
--version-VPrint the CLI version–
--help-hPrint help–
Examples
Basic Comparison
compare-json '{"name":"Alice","age":30}' '{"name":"Bob","age":30}'

Output:

┌─────────────┬──────────────┐
│ Key         │ Change Type  │
├─────────────┼──────────────┤
│ (Base) name │ valueChanged │
└─────────────┴──────────────┘
Compare Files
compare-json base.json contrast.json
Array Comparison Methods
# By index (default)
compare-json '[1,2,3]' '[2,3,4]'

# LCS — minimal diff for ordered arrays
compare-json '[1,2,3]' '[2,3,4]' -a lcs
compare-json '[1,2,3]' '[2,3,4]' --array-compare-method lcs

# Unordered — treat as multisets
compare-json '[1,2,3]' '[3,2,1]' -a unordered
compare-json '[1,2,3]' '[3,2,1]' --array-compare-method unordered
Case-Insensitive Comparison
# Case-insensitive keys
compare-json '{"Name":"Alice"}' '{"name":"Alice"}' -k
compare-json '{"Name":"Alice"}' '{"name":"Alice"}' --key-case-insensitive

# Case-insensitive values
compare-json '{"status":"OK"}' '{"status":"ok"}' -v
compare-json '{"status":"OK"}' '{"status":"ok"}' --value-case-insensitive
Numeric String Comparison
compare-json '{"count":1}' '{"count":"1"}' --numeric-string-equals-number
JSON Output
compare-json file1.json file2.json -j
compare-json file1.json file2.json --json-export

Output:

[
  {
    "pathSegments": ["name"],
    "pathString": "name",
    "pathBelongsTo": "both",
    "diffType": "valueChanged"
  }
]
Save to File
# Save table format
compare-json file1.json file2.json -o diff.txt

# Save JSON format
compare-json file1.json file2.json -j -o diff.json

When -o is set, the CLI writes the formatted result to the file and prints Output written to <path> to stdout.

Output Format
Table Format (Default)

A Unicode box-drawn table. Each row is labeled with the side that owns the path:

  • (Base) <path> — the path exists on the base side (value or type changes, deletions).
  • (Contrast) <path> — the path exists only on the contrast side (additions).
  • (Root) — used when the top-level value itself differs.
┌──────────────┬──────────────┐
│ Key          │ Change Type  │
├──────────────┼──────────────┤
│ (Base) a     │ valueChanged │
│ (Base) b     │ deleted      │
│ (Contrast) c │ added        │
└──────────────┴──────────────┘

When the two inputs match exactly, the output is simply:

No differences found
JSON Format
[
  {
    "pathSegments": ["name"],
    "pathString": "name",
    "pathBelongsTo": "both",
    "diffType": "valueChanged"
  },
  {
    "pathSegments": ["age"],
    "pathString": "age",
    "pathBelongsTo": "base",
    "diffType": "deleted"
  },
  {
    "pathSegments": ["email"],
    "pathString": "email",
    "pathBelongsTo": "contrast",
    "diffType": "added"
  }
]

See JSONValueDifference in @compare-json/core for the full shape.

Difference Types
TypeDescription
addedValue exists in contrast but not in base.
deletedValue exists in base but not in contrast.
typeChangedValue type changed between base and contrast (e.g. number → string).
valueChangedValue changed while the type stayed the same.

MCP Server

@compare-json/cli also ships an MCP (Model Context Protocol) server that exposes the comparison engine as a tool for AI assistants.

Start the MCP Server
# from a global install
compare-json --mcp

# or via npx
npx @compare-json/cli --mcp

The server communicates over stdio.

Available Tools
compare_json

Compare two JSON values and return their differences.

Input parameters:

ParameterTypeRequiredDescription
baseJSONanyconditionalBase JSON value (already parsed).
baseJSONStringstringconditionalBase JSON as a stringified value (parsed by the server).
baseJSONFilePathstringconditionalPath to a base JSON file (read and parsed by the server).
contrastJSONanyconditionalContrast JSON value (already parsed).
contrastJSONStringstringconditionalContrast JSON as a stringified value.
contrastJSONFilePathstringconditionalPath to a contrast JSON file.
optionsobjectNoComparison options (see below).

At least one of baseJSON / baseJSONString / baseJSONFilePath must be provided, and at least one of contrastJSON / contrastJSONString / contrastJSONFilePath. When more than one is set for a side, file path takes precedence, then string, then raw value.

Options:

OptionTypeDefaultDescription
arrayCompareMethod'byIndex' | 'lcs' | 'unordered''byIndex'Array comparison strategy.
keyCaseInsensitivebooleanfalseCase-insensitive key comparison.
valueCaseInsensitivebooleanfalseCase-insensitive value comparison.
numericStringEqualsNumberbooleanfalseTreat numeric strings as equal to numbers.

Output:

Returns structuredContent.differences — an array of JSONValueDifference objects — and a content[0].text mirror of the same data as JSON text.

{
  "differences": [
    {
      "pathSegments": ["name"],
      "pathString": "name",
      "pathBelongsTo": "both",
      "diffType": "valueChanged"
    }
  ]
}
MCP Client Configuration

Add the following to your MCP client config (e.g. mcp.json):

{
  "mcpServers": {
    "compare-json": {
      "command": "npx",
      "args": ["@compare-json/cli@latest", "--mcp"]
    }
  }
}

License

MIT

Comments

Markdown supported

New to MCP?

From what the protocol is to installing your first server, these answers cover most first questions.

An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.