https://github.com/dolmen-go/jsonptr
JSON Pointer (RFC 6901) for Go
https://github.com/dolmen-go/jsonptr
go golang golang-module golang-package json-pointer rfc6901
Last synced: 16 days ago
JSON representation
JSON Pointer (RFC 6901) for Go
- Host: GitHub
- URL: https://github.com/dolmen-go/jsonptr
- Owner: dolmen-go
- License: apache-2.0
- Created: 2016-10-02T21:14:21.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-03-28T01:01:18.000Z (about 1 year ago)
- Last Synced: 2025-03-23T23:36:13.046Z (about 1 month ago)
- Topics: go, golang, golang-module, golang-package, json-pointer, rfc6901
- Language: Go
- Homepage: https://pkg.go.dev/github.com/dolmen-go/jsonptr
- Size: 79.1 KB
- Stars: 30
- Watchers: 3
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jsonptr - JSON Pointer ([RFC 6901](https://tools.ietf.org/html/rfc6901)) for Go
[](https://godoc.org/github.com/dolmen-go/jsonptr)
[](https://codecov.io/gh/dolmen-go/jsonptr)
[](https://goreportcard.com/report/github.com/dolmen-go/jsonptr)## Features
Goals:
1. First-class interface
* Idiomatic
* Short
* Complete
* Structured errors, not just strings: [`BadPointerError`](https://godoc.org/github.com/dolmen-go/jsonptr#BadPointerError), [`PtrError`](https://godoc.org/github.com/dolmen-go/jsonptr#PtrError), [`DocumentError`](https://godoc.org/github.com/dolmen-go/jsonptr#DocumentError)
* Working at JSON data model level (tree of `[]interface{}`, `map[string]interface{}`) as well as serialized JSON ([`json.RawMessage`](https://golang.org/pkg/encoding/json/#RawMessage), [`json.Decoder`](https://golang.org/pkg/encoding/json/#Decoder))
2. Correctness (most existing open source Go implementations have limitations in their interface or have implementation bugs)
* Full testsuite (work in progress)
* Reject invalid escapes (regexp `/~[^01]/`)
* Allow any JSON value as leaf node
* Allow any JSON value as root (not just a `map[string]interface{}`)
* Allow to get/set the root of the document with the empty pointer `""`
3. Speed (see [benchmark](https://github.com/dolmen-go/jsonptr-benchmark))
* No reflect
* Optimised parsing## Example
```go
package mainimport (
"fmt"
"github.com/dolmen-go/jsonptr"
)func main() {
// JSON: { "a": [ 1 ] }
document := map[string]interface{}{
"a": []interface{}{
1,
},
}val, err := jsonptr.Get(document, `/a/0`)
if err != nil {
fmt.Printf("Error: %s\n", err)
} else {
fmt.Printf("Got: %v\n", val)
}
}
```## Status
Production ready.
The aim is code coverage of 100%. Use go coverage tools and consider any
code not covered by the testsuite as never tested and full of bugs.Todo:
* tests of error cases## License
Copyright 2016-2020 Olivier Mengué
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.