Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vdbulcke/json-patcher
CLI tool to apply JSON Patch (RFC 6902)
https://github.com/vdbulcke/json-patcher
cli json-patch rfc-6902 tui
Last synced: about 2 months ago
JSON representation
CLI tool to apply JSON Patch (RFC 6902)
- Host: GitHub
- URL: https://github.com/vdbulcke/json-patcher
- Owner: vdbulcke
- Created: 2023-03-04T14:14:22.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-01T11:07:53.000Z (about 1 year ago)
- Last Synced: 2024-04-20T09:09:12.523Z (9 months ago)
- Topics: cli, json-patch, rfc-6902, tui
- Language: Go
- Homepage:
- Size: 603 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
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](https://kubectl.docs.kubernetes.io/references/kustomize/builtins/#_patchesjson6902_) but for arbitrary JSON files.
At it's core it is using the ["github.com/evanphx/json-patch/v5"](https://github.com/evanphx/json-patch) library.
## Install
Download the binaries from the [releases](https://github.com/vdbulcke/json-patcher/releases) page.
### Validate Signature With Cosign
Make sure you have `cosign` installed locally (see [Cosign Install](https://docs.sigstore.dev/cosign/installation/)).
Then you can use the `./verify_signature.sh` in this repo:
```bash
./verify_signature.sh PATH_TO_DOWNLOADED_ARCHIVE TAG_VERSION
```
for example
```bash
$ ./verify_signature.sh ~/Downloads/json-patcher_0.1.0_Linux_x86_64.tar.gz v0.1.0Checking Signature for version: v0.1.0
Verified OK```
### Add To PATH
```bash
sudo mv json-patcher /usr/local/bin/
```## Getting Started
Create a patch file `patch.yaml`:
```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
```bash
json-patcher apply -p patch.yaml
```See the result
```bash
$ cat generated.json
{"foo":"baz","hello":"world"}
```See [./example/patch.yaml](./example/patch.yaml) for details information about configuration of patches.
## CLI Usage
See [json-patcher](./doc/json-patcher.md) for CLI usage.
## Completion
See [json-patcher completion](./doc/json-patcher_completion.md).
## Interactive Terminal UI
`json-patcher interactive` leverages [charmbracelet/bubbletea](https://github.com/charmbracelet/bubbletea) to display an interactive applications within your terminal.
Start the TUI with:
```bash
json-patcher interactive -p patch.yaml
```
> NOTE: `json-patcher interactive` supports the same arguments as `json-patcher apply` subcommand> The above example was generated with VHS ([view source](./example/demo.tape)).
### List View
The list view will display the list of patches (filtered by `source_not_exist` and `--skip-tags`).
Key Binding
| Key | Action |
| -- | -- |
| Arrow UP | Move up the list |
| Arrow DOWN | Move Down the list |
| Arrow LEFT | Move left the pager |
| Arrow RIGHT | Move right the pager |
| ENTER | View Current Patch |
| x | Delete patch from list |
| / | Trigger fuzzy filter |
| ? | Help |
| q | Quit |
| CTRL+C | Quit |### Current Patch View
Key Binding
| Key | Action |
| -- | -- |
| Arrow UP | Move up the pager |
| Arrow DOWN | Move Down the pager |
| p | Preview Current Patch |
| t | Toggle `--allow-unescaped-html` flag |
| a | Apply current Patch **(*)** |
| q | Back |
| ESC | Back |
| CTRL+C | Quit |> **(*)** 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.