GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - mattbaird/jsonpatch: As per http://jsonpatch.com/ JSON Patch is specified in RFC 6902 from the IETF.

BranchesTags
Open more actions menu

Latest commit

 

History

30 Commits
30 Commits

Folders and files

NameName
Last commit message
Last commit date
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
jsonpatch.go
jsonpatch.go
 
 
jsonpatch_array_at_root_test.go
jsonpatch_array_at_root_test.go
 
 
jsonpatch_array_test.go
jsonpatch_array_test.go
 
 
jsonpatch_complex_test.go
jsonpatch_complex_test.go
 
 
jsonpatch_geojson_test.go
jsonpatch_geojson_test.go
 
 
jsonpatch_hypercomplex_test.go
jsonpatch_hypercomplex_test.go
 
 
jsonpatch_json_test.go
jsonpatch_json_test.go
 
 
jsonpatch_simple_test.go
jsonpatch_simple_test.go
 
 
jsonpatch_supercomplex_test.go
jsonpatch_supercomplex_test.go
 
 

Repository files navigation

jsonpatch

As per http://jsonpatch.com/ JSON Patch is specified in RFC 6902 from the IETF.

JSON Patch allows you to generate JSON that describes changes you want to make to a document, so you don't have to send the whole doc. JSON Patch format is supported by HTTP PATCH method, allowing for standards based partial updates via REST APIs.

go get github.com/mattbaird/jsonpatch

I tried some of the other "jsonpatch" go implementations, but none of them could diff two json documents and generate format like jsonpatch.com specifies. Here's an example of the patch format:

[
  { "op": "replace", "path": "/baz", "value": "boo" },
  { "op": "add", "path": "/hello", "value": ["world"] },
  { "op": "remove", "path": "/foo"}
]

The API is super simple #example

package main

import (
	"fmt"
	"github.com/mattbaird/jsonpatch"
)

var simpleA = `{"a":100, "b":200, "c":"hello"}`
var simpleB = `{"a":100, "b":200, "c":"goodbye"}`

func main() {
	patch, e := jsonpatch.CreatePatch([]byte(simpleA), []byte(simpleB))
	if e != nil {
		fmt.Printf("Error creating JSON patch:%v", e)
		return
	}
	for _, operation := range patch {
		fmt.Printf("%s\n", operation.Json())
	}
}

This code needs more tests, as it's a highly recursive, type-fiddly monster. It's not a lot of code, but it has to deal with a lot of complexity.

About

As per http://jsonpatch.com/ JSON Patch is specified in RFC 6902 from the IETF.

Resources

Readme
Apache-2.0 license
Activity

Stars

138 stars

Watchers

6 watching

Forks

49 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.