yaml-patch is a version of Evan Phoenix's json-patch, which is an implementation of JSON Patch, directly transposed to YAML

Related tags

Utilities yaml-patch
Overview

yaml-patch

yaml-patch is a version of Evan Phoenix's json-patch, which is an implementation of JavaScript Object Notation (JSON) Patch, directly transposed to YAML.

Syntax

General syntax is the following:

- op: 
   
  from: 
    
   # only valid for the 'move' and 'copy' operations
  path: 
    
   # always mandatory
  value: 
    
   # only valid for 'add', 'replace' and 'test' operations

Paths

Supported YAML path are primarily those of RFC 6901 JSON Pointers.

A syntax extention with = was added to match any sub-element in a YAML structure by key/value.

For example, the following removes all sub-nodes of the releases array that have a name key with a value of cassandra:

- op: remove
  path: /releases/name=cassandra

A major caveat with =, is that it actually performs a recursive search for matching nodes. The root node at which the recursive search is initiated, is the node matched by the path prefix before =.

The second caveat is that the recursion stops at a matching node. With the add operation, you could expect sub-nodes of matching nodes to also match, but they don't.

If your document is the following and you apply the patch above, then all sub-nodes of /releases that match name=cassandra will be removed.

releases: # a recursive search is made, starting from this node
  - name: cassandra # does match, will be removed
  - - name: toto
    - name: cassandra # does match, will be removed!
      sub:
        - name: cassandra # not matched: the recursion stops at matching parent node
  - super:
      sub:
        name: cassandra # does match, will be removed!

Path Escaping

As in RFC 6901, escape sequences are introduced by ~. So, ~ is escaped ~0, / is escaped ~1. There is no escape for = yet.

Operations

Supported patch operations are those of RFC 6902.

Installing

go get github.com/krishicks/yaml-patch

If you want to use the CLI:

go get github.com/krishicks/yaml-patch/cmd/yaml-patch

API

Given the following RFC6902-ish YAML document, ops:

---
- op: add
  path: /baz/waldo
  value: fred

And the following YAML that is to be modified, src:

---
foo: bar
baz:
  quux: grault

Decode the ops file into a patch:

patch, err := yamlpatch.DecodePatch(ops)
// handle err

Then apply that patch to the document:

dst, err := patch.Apply(src)
// handle err

// do something with dst

Example

doc := []byte(`---
foo: bar
baz:
  quux: grault
`)

ops := []byte(`---
- op: add
  path: /baz/waldo
  value: fred
`)

patch, err := yamlpatch.DecodePatch(ops)
if err != nil {
  log.Fatalf("decoding patch failed: %s", err)
}

bs, err := patch.Apply(doc)
if err != nil {
  log.Fatalf("applying patch failed: %s", err)
}

fmt.Println(string(bs))
baz:
  quux: grault
  waldo: fred
foo: bar
Releases(v0.0.10)
Owner
Steve Coffman
•ა꧁シ He / Him シ꧂ა• 【ツ】⬆️
Steve Coffman
CUE utilities and helpers for working with tree based objects in any combination of CUE, Yaml, and JSON.

Cuetils CUE utilities and helpers for working with tree based objects in any combination of CUE, Yaml, and JSON. Using As a command line binary The cu

_Hofstadter 46 May 7, 2022
Optimal implementation of ordered maps for Golang - ie maps that remember the order in which keys were inserted.

Goland Ordered Maps Same as regular maps, but also remembers the order in which keys were inserted, akin to Python's collections.OrderedDicts. It offe

Jean Rougé 183 May 17, 2022
A Go (golang) library for parsing and verifying versions and version constraints.

go-version is a library for parsing versions and version constraints, and verifying versions against a set of constraints. go-version can sort a collection of versions properly, handles prerelease/beta versions, can increment versions, etc.

HashiCorp 1.1k May 10, 2022
Yet another semantic version incrementor and tagger for git

git-tag-inc Increments the version number and tags it. (You will need to push) Usage ./git-tag-inc [major] [minor] [release] [test] [uat] git-tag-in

Arran Ubels 6 Apr 30, 2022
simple GitHub action to parse Markdown Links into a .yaml file for Hugo

Obsidian Link Scrapper Used by Quartz This repository comes to you in two parts. GitHub Action (scrapes links into a .yml file) Hugo Partial (turns .y

Jacky Zhao 40 May 15, 2022
Split multiple Kubernetes files into smaller files with ease. Split multi-YAML files into individual files.

Split multiple Kubernetes files into smaller files with ease. Split multi-YAML files into individual files.

Patrick D'appollonio 154 May 18, 2022
Split multiple Kubernetes files into smaller files with ease. Split multi-YAML files into individual files.

kubectl-slice: split Kubernetes YAMLs into files kubectl-slice is a neat tool that allows you to split a single multi-YAML Kubernetes manifest into mu

Patrick D'appollonio 153 May 16, 2022
Goridge is high performance PHP-to-Golang codec library which works over native PHP sockets and Golang net/rpc package.

Goridge is high performance PHP-to-Golang codec library which works over native PHP sockets and Golang net/rpc package. The library allows you to call Go service methods from PHP with a minimal footprint, structures and []byte support.

Spiral Scout 1.1k May 18, 2022
This is a Pub/Sub for the Watermill project which uses the Bolt database.

Watermill Bolt Pub/Sub This is a Pub/Sub for the Watermill project which uses the Bolt database.

Three Dots Labs 5 Dec 1, 2021
Simple go package which converts roman strings to integer

romanparse Simple go package which converts roman strings

Caio Ribeiro Pereira 2 Oct 6, 2021
A lib of golang which contains many funny api;

A lib of golang which contains many funny api; I created it cause I could not find these more-effient apis from other repo.

acehinnnqru 1 Oct 27, 2021
Utility to restrict which package is allowed to import another package.

go-import-rules Utility to restrict which package is allowed to import another package. This tool will read import-rules.yaml or import-rules.yml in t

PAYFAZZ 0 Jan 7, 2022
ms - 'my story' creates a secure password string which can be memorized with a technique shared by Max.

On 23.12.21 20:22, Stefan Claas wrote: [...] > > Yes, I am aware of that, but how can one memorize a key when traveling > and not taking any devices

Stefan Claas 0 Dec 24, 2021
Cpu-profiling - Basic example of CPU Profiling in Golang which shows the bottlenecks and how much time is spent per function

cpu-profiling Basic example of CPU Profiling in Golang which shows the bottlenec

Felipe Azevedo 0 Jan 4, 2022
Flock is a project which provides a Go solution for system level file locks for all platforms Golang supports.

Flock is a project which provides a Go solution for system level file locks for all platforms Golang supports.

Ken Sipe 0 Feb 8, 2022
go implementation of timsort

timsort timsort is a Go implementation of Tim Peters's mergesort sorting algorithm. For many input types it is 2-3 times faster than Go's built-in sor

Philip Silva 71 Mar 15, 2022
Implementation of do255e and do255s in Go

Go Implementation of do255e and do255s This is a plain Go implementation of do255e and do255s. It is considered secure; all relevant functions should

null 20 Dec 22, 2021
Go implementation of the Heaven's Gate technique

gopherheaven is a Go implementation of the classic Heaven's Gate technique originally published by roy g biv on VX Heaven in 2009. gopherheaven can be used as an evasion technique to directly call 64-bit code from a 32-bit process.

aus 65 Mar 12, 2022
Lightweight, Simple, Quick, Thread-Safe Golang Stack Implementation

stack Lightweight, Simple, Quick, Thread-Safe Golang Stack Implementation Purpose Provide a fast, thread safe, and generic Golang Stack API with minim

Brendan Wilson 5 May 3, 2022