examples/

directory
v0.2.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2026 License: MIT

README

Examples

Examples for the JSON Merge Patch (RFC 7386) implementation.

Quick Start

Choose an example to run:

go run ./examples/struct-merge
go run ./examples/map-merge
go run ./examples/json-string-merge
go run ./examples/json-bytes-merge

Example Structure

Each directory focuses on one document form:

  • struct-merge — type-safe struct operations
  • map-merge — dynamic map data operations
  • json-string-merge — JSON string processing
  • json-bytes-merge — JSON byte processing

Core Concepts

RFC 7386 Key Behaviors
  1. Recursive object merging — nested objects are merged recursively.
  2. null deletes fieldsnull values remove target fields.
  3. Array replacement — arrays are replaced entirely, not element by element.
  4. New field addition — new fields from the patch are added to the target.
Supported Document Types
  • struct — type-safe documents converted through JSON
  • map[string]any — dynamic object form
  • string — valid JSON strings or raw string scalar values
  • []byte — valid JSON byte slices

Directories

Path Synopsis
Package main demonstrates byte-slice JSON Merge Patch usage.
Package main demonstrates byte-slice JSON Merge Patch usage.
Package main demonstrates string-based JSON Merge Patch usage.
Package main demonstrates string-based JSON Merge Patch usage.
Package main demonstrates map-based JSON Merge Patch usage.
Package main demonstrates map-based JSON Merge Patch usage.
Package main demonstrates struct-based JSON Merge Patch usage.
Package main demonstrates struct-based JSON Merge Patch usage.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL