Categorygithub.com/vdbulcke/json-patcher
modulepackage
0.4.1
Repository: https://github.com/vdbulcke/json-patcher.git
Documentation: pkg.go.dev

# README

JSON Patcher

Description

json-patcher is a CLI tools to applying a list of JSON patch (rfc6902) from a declarative config file. Think of it as kustomize patch but for arbitrary JSON files.

At it's core it is using the "github.com/evanphx/json-patch/v5" library.

Install

Download the binaries from the releases page.

Validate Signature With Cosign

Make sure you have cosign installed locally (see Cosign Install).

Then you can use the ./verify_signature.sh in this repo:

./verify_signature.sh PATH_TO_DOWNLOADED_ARCHIVE TAG_VERSION

for example

$ ./verify_signature.sh ~/Downloads/json-patcher_0.1.0_Linux_x86_64.tar.gz v0.1.0

Checking Signature for version: v0.1.0
Verified OK

Add To PATH

sudo mv json-patcher /usr/local/bin/

Getting Started

Create a patch file patch.yaml:

---
## List of patches
patches:

## Patch on a source and a destination
- 
  ## source:  same as '{}' as source file
  source: NEW
  ## destination: where the json should be written after 
  ##              all patches have been applied
  destination: ./generated.json
  json_patch: |-
    ## this is a first patch 
    - op: add
      path: "/foo"
      value: "baz"
    ## this is a second patch 
    - op: add
      path: "/hello"
      value: "world"

## You can add here another list of json_patch to another sources and/or destinations

Apply the patch

json-patcher apply -p patch.yaml

See the result

$ cat generated.json 
{"foo":"baz","hello":"world"}

See ./example/patch.yaml for details information about configuration of patches.

CLI Usage

See json-patcher for CLI usage.

Completion

See json-patcher completion.

Interactive Terminal UI

json-patcher interactive leverages charmbracelet/bubbletea to display an interactive applications within your terminal.

Start the TUI with:

json-patcher interactive -p patch.yaml

NOTE: json-patcher interactive supports the same arguments as json-patcher apply subcommand

<img src=./example/demo.gif width="700"/>

The above example was generated with VHS (view source).

List View

The list view will display the list of patches (filtered by source_not_exist and --skip-tags).

Key Binding

KeyAction
Arrow UPMove up the list
Arrow DOWNMove Down the list
Arrow LEFTMove left the pager
Arrow RIGHTMove right the pager
ENTERView Current Patch
xDelete patch from list
/Trigger fuzzy filter
?Help
qQuit
CTRL+CQuit

Current Patch View

Key Binding

KeyAction
Arrow UPMove up the pager
Arrow DOWNMove Down the pager
pPreview Current Patch
tToggle --allow-unescaped-html flag
aApply current Patch (*)
qBack
ESCBack
CTRL+CQuit

(*) If teh current patch's Destination is STDOUT "applying" the patch is the same as "previewing" the patch

NOTE: same Key binding for "Current Patch Info", "Preview Patch", and "Apply Patch Result" view.

# Packages

No description provided by the author