{"id":28892864,"url":"https://github.com/kaptinlin/jsonpatch","last_synced_at":"2026-04-28T01:32:10.313Z","repository":{"id":299253783,"uuid":"1001227161","full_name":"kaptinlin/jsonpatch","owner":"kaptinlin","description":"Go library for JSON Patch (RFC 6902) with extended operations and JSON Predicate support","archived":false,"fork":false,"pushed_at":"2026-04-19T01:23:49.000Z","size":2405,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-19T02:36:48.274Z","etag":null,"topics":["json","jsonpatch"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kaptinlin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2025-06-13T03:15:46.000Z","updated_at":"2026-04-19T01:23:54.000Z","dependencies_parsed_at":"2025-06-15T16:27:47.655Z","dependency_job_id":"fc6239ee-b4f5-444c-a15d-baa0048b1705","html_url":"https://github.com/kaptinlin/jsonpatch","commit_stats":null,"previous_names":["kaptinlin/jsonpatch"],"tags_count":38,"template":false,"template_full_name":null,"purl":"pkg:github/kaptinlin/jsonpatch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaptinlin%2Fjsonpatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaptinlin%2Fjsonpatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaptinlin%2Fjsonpatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaptinlin%2Fjsonpatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kaptinlin","download_url":"https://codeload.github.com/kaptinlin/jsonpatch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaptinlin%2Fjsonpatch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32362781,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-27T20:07:02.737Z","status":"ssl_error","status_checked_at":"2026-04-27T20:07:00.910Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json","jsonpatch"],"created_at":"2025-06-21T02:06:52.797Z","updated_at":"2026-04-28T01:32:10.308Z","avatar_url":"https://github.com/kaptinlin.png","language":"Go","readme":"# JSON Patch Go\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/kaptinlin/jsonpatch.svg)](https://pkg.go.dev/github.com/kaptinlin/jsonpatch)\n[![Go Report Card](https://goreportcard.com/badge/github.com/kaptinlin/jsonpatch)](https://goreportcard.com/report/github.com/kaptinlin/jsonpatch)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nA Go library for RFC 6902 JSON Patch plus predicate and extended operations with type-preserving APIs\n\n\u003e json-joy compatible: this package follows the JSON Patch, predicate, and extended-operation behavior used by [streamich/json-joy](https://github.com/streamich/json-joy/tree/master/src/json-patch).\n\n## Features\n\n- **Type-preserving results**: `ApplyPatch`, `ApplyOp`, and `ApplyOps` preserve the input document shape whenever the result can be converted back safely.\n- **Broad operation support**: Use RFC 6902 operations, predicate operations, and extended operations in one package.\n- **Multiple document shapes**: Patch `map[string]any`, structs, `[]byte`, JSON strings, plain strings, primitives, and `[]any`.\n- **Executable operations**: Build operations with the `op` package when you want typed operation values instead of JSON-shaped payloads.\n- **Codec support**: Encode and decode operations through `codec/json`, `codec/compact`, and `codec/binary`.\n- **Predictable defaults**: Patch application is immutable unless you pass `jsonpatch.WithMutate(true)`.\n\n## Installation\n\n```bash\ngo get github.com/kaptinlin/jsonpatch\n```\n\n## Quick Start\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"log\"\n\n    \"github.com/kaptinlin/jsonpatch\"\n)\n\nfunc main() {\n    doc := map[string]any{\n        \"name\": \"John\",\n        \"tags\": []any{\"golang\"},\n    }\n\n    patch := []jsonpatch.Operation{\n        {Op: \"test\", Path: \"/name\", Value: \"John\"},\n        {Op: \"replace\", Path: \"/name\", Value: \"Jane\"},\n        {Op: \"add\", Path: \"/email\", Value: \"jane@example.com\"},\n    }\n\n    result, err := jsonpatch.ApplyPatch(doc, patch)\n    if err != nil {\n        log.Fatal(err)\n    }\n\n    fmt.Println(result.Doc[\"name\"])\n    fmt.Println(result.Doc[\"email\"])\n    fmt.Println(doc[\"name\"])\n}\n```\n\n## API Overview\n\n| API | Use when |\n| --- | --- |\n| `ApplyPatch` | You already have JSON-shaped `[]Operation` values. |\n| `ApplyOp` | You want to execute one compiled operation from `op/`. |\n| `ApplyOps` | You want to execute compiled operations directly. |\n| `ValidateOperation` / `ValidateOperations` | You want to validate JSON-shaped operation payloads before applying them. |\n\n## Executable Operations\n\nUse `op/` when you want operation values with methods such as `Validate`, `ToJSON`, and `ToCompact`.\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"log\"\n\n    \"github.com/kaptinlin/jsonpatch\"\n    \"github.com/kaptinlin/jsonpatch/op\"\n)\n\ntype User struct {\n    Name   string   `json:\"name\"`\n    Active bool     `json:\"active\"`\n    Roles  []string `json:\"roles\"`\n}\n\nfunc main() {\n    user := User{Name: \"John\", Active: true, Roles: []string{\"admin\"}}\n\n    ops := []jsonpatch.Op{\n        op.NewTest([]string{\"active\"}, true),\n        op.NewReplace([]string{\"name\"}, \"Jane\"),\n        op.NewAdd([]string{\"roles\", \"-\"}, \"owner\"),\n    }\n\n    result, err := jsonpatch.ApplyOps(user, ops)\n    if err != nil {\n        log.Fatal(err)\n    }\n\n    fmt.Println(result.Doc.Name)\n    fmt.Println(result.Doc.Roles)\n}\n```\n\n## Document Shapes\n\n| Input | Processing model | Output |\n| --- | --- | --- |\n| `map[string]any` | Apply directly | `map[string]any` |\n| `[]byte` | Decode JSON, apply, encode JSON | `[]byte` |\n| `string` starting with `{` or `[` | Decode JSON, apply, encode JSON | `string` |\n| Other `string` | Treat as a plain string value | `string` |\n| Structs and concrete types | Marshal to JSON, apply, unmarshal back | Original Go type |\n| Primitives and `[]any` | Apply directly when assignable | Original Go type |\n\n## Codecs\n\n### Compact Codec\n\nUse `codec/compact` when you want the array-based wire format.\n\n```go\nops := []jsonpatch.Op{\n    op.NewAdd([]string{\"name\"}, \"Jane\"),\n    op.NewInc([]string{\"version\"}, 1),\n}\n\nencoded, err := compact.EncodeJSON(ops)\nif err != nil {\n    log.Fatal(err)\n}\n\ndecoded, err := compact.DecodeJSON(encoded)\nif err != nil {\n    log.Fatal(err)\n}\n\nfmt.Println(len(decoded))\n```\n\n### Binary Codec\n\nUse `codec/binary` when you want MessagePack encoding for executable operations.\nSecond-order predicates (`and`, `or`, `not`) are not supported by the binary codec.\n\n```go\ncodec := binary.New()\n\ndata, err := codec.Encode(ops)\nif err != nil {\n    log.Fatal(err)\n}\n\ndecoded, err := codec.Decode(data)\nif err != nil {\n    log.Fatal(err)\n}\n\nfmt.Println(len(decoded))\n```\n\n## Examples\n\nExplore the runnable examples in [`examples/`](examples/):\n\n- [`examples/basic-operations/`](examples/basic-operations/)\n- [`examples/array-operations/`](examples/array-operations/)\n- [`examples/conditional-operations/`](examples/conditional-operations/)\n- [`examples/copy-move-operations/`](examples/copy-move-operations/)\n- [`examples/string-operations/`](examples/string-operations/)\n- [`examples/struct-patch/`](examples/struct-patch/)\n- [`examples/map-patch/`](examples/map-patch/)\n- [`examples/json-bytes-patch/`](examples/json-bytes-patch/)\n- [`examples/json-string-patch/`](examples/json-string-patch/)\n- [`examples/compact-codec/`](examples/compact-codec/)\n- [`examples/binary-codec/`](examples/binary-codec/)\n- [`examples/error-handling/`](examples/error-handling/)\n- [`examples/mutate-option/`](examples/mutate-option/)\n- [`examples/batch-update/`](examples/batch-update/)\n\n## Development\n\n```bash\ntask test\ntask lint\ntask markdownlint\n```\n\nFor development guidelines, see [AGENTS.md](AGENTS.md).\nFor technical contracts, see [SPECS/](SPECS/).\n\n## Contributing\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md).\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaptinlin%2Fjsonpatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaptinlin%2Fjsonpatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaptinlin%2Fjsonpatch/lists"}