Get the FREE Ultimate OpenClaw Setup Guide →
w

Json Modifier

Scanned

@wanng-ide

npx machina-cli add skill @wanng-ide/json-modifier --openclaw
Files (1)
SKILL.md
1.4 KB

JSON Modifier

A utility for modifying JSON files using RFC 6902 JSON Patch format. Supports precise additions, removals, replacements, moves, copies, and tests.

Usage

# Modify a file in place
node skills/json-modifier/index.js --file path/to/config.json --patch '[{"op": "replace", "path": "/key", "value": "new_value"}]'

# Modify and save to a new file
node skills/json-modifier/index.js --file input.json --patch '[...]' --out output.json

# Use a patch file
node skills/json-modifier/index.js --file input.json --patch-file patches/update.json

Patch Format (RFC 6902)

The patch must be a JSON array of operation objects.

Examples

Replace a value:

[
  { "op": "replace", "path": "/version", "value": "2.0.0" }
]

Add a new key:

[
  { "op": "add", "path": "/features/new_feature", "value": true }
]

Remove a key:

[
  { "op": "remove", "path": "/deprecated_key" }
]

Append to an array:

[
  { "op": "add", "path": "/list/-", "value": "item" }
]

Safety

  • Validates patch against document before applying.
  • Atomic write (writes to temporary file, then renames).
  • Preserves indentation (default: 2 spaces).

Source

git clone https://clawhub.ai/wanng-ide/json-modifierView on GitHub

Overview

Json Modifier applies RFC 6902 JSON patches to JSON documents. It supports precise additions, removals, replacements, moves, copies, and tests, enabling safe in-place updates of config files, package.json, or in-memory JSON without brittle rewrites.

How This Skill Works

The tool loads the JSON document, validates the patch array against it, and applies the RFC 6902 operations (add, remove, replace, move, copy, test). It then writes the result atomically via a temporary file and preserves indentation (default 2 spaces) unless customized.

When to Use It

  • Patch a config.json in place without rewriting the whole file.
  • Update dependencies or scripts in package.json via a patch.
  • Modify an in-memory JSON object before persisting changes.
  • Automate config updates in CI/CD by applying patch files.
  • Safely alter nested keys with explicit JSON Pointer paths instead of regex.

Quick Start

  1. Step 1: Run the command to patch a file. Example: node skills/json-modifier/index.js --file path/to/config.json --patch '[{"op": "replace", "path": "/key", "value": "new_value"}]'
  2. Step 2: If desired, write the result to a new file with --out or apply a patch file with --patch-file patches/update.json
  3. Step 3: Verify the updated file and confirm indentation was preserved (default is 2 spaces)

Best Practices

  • Ensure patches are valid against the target document before applying.
  • Back up original files or work on a copy before patching.
  • Use a patch file for large or collaborative patches to improve traceability.
  • Prefer explicit paths and test changes in a dev environment.
  • Rely on atomic writes to avoid partial updates and preserve indentation.

Example Use Cases

  • Replace /version with 2.0.0 in config.json.
  • Add /features/new_feature with value true.
  • Remove /deprecated_key from the document.
  • Append 'item' to the end of an array at /list using /list/-.
  • Patch package.json to adjust dependencies or scripts via a patch file.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers