Go implementation of JSON Pointer (RFC 6901) for navigating
and mutating JSON documents represented as Go values. Works with map[string]any, slices, and Go structs
(resolved via json struct tags and reflection).
| File | Contents |
|---|---|
pointer.go |
Core types (Pointer, JSONPointable, JSONSetable), New, Get, Set, Offset, Escape/Unescape |
errors.go |
Sentinel errors: ErrPointer, ErrInvalidStart, ErrUnsupportedValueType |
New(string) (Pointer, error)— parse a JSON pointer string (e.g."/foo/0/bar")Pointer.Get(document any) (any, reflect.Kind, error)— retrieve a valuePointer.Set(document, value any) (any, error)— set a value (document must be pointer/map/slice)Pointer.Offset(jsonString string) (int64, error)— byte offset of token in raw JSONGetForToken/SetForToken— single-level convenience helpersEscape/Unescape— RFC 6901 token escaping (~0↔~,~1↔/)
Custom types can implement JSONPointable (for Get) or JSONSetable (for Set) to bypass reflection.
- Struct fields must have a
jsontag to be reachable; untagged fields are ignored. - Anonymous embedded struct fields are traversed only if tagged.
- The RFC 6901
"-"array suffix (append) is not implemented.
github.com/go-openapi/swag/jsonname— struct tag to JSON field name resolutiongithub.com/go-openapi/testify/v2— test-only assertions (zero-dep fork ofstretchr/testify)
- All
.gofiles must have SPDX license headers (Apache-2.0). - Commits require DCO sign-off (
git commit -s). - Linting:
golangci-lint run— config in.golangci.yml(posture:default: allwith explicit disables). - Every
//nolintdirective must have an inline comment explaining why. - Tests:
go test ./...with-race. CI runs on{ubuntu, macos, windows} x {stable, oldstable}. - Test framework:
github.com/go-openapi/testify/v2(notstretchr/testify).
See .github/copilot/ (symlinked to .claude/rules/) for detailed rules on Go conventions, linting, testing, and contributions.