mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-01 13:18:41 +00:00
91d37be1da
* github.com/Microsoft/go-winio * github.com/bradrydzewski/togo * github.com/containerd/containerd * github.com/docker/cli * github.com/docker/docker * github.com/docker/docker-credential-helpers * github.com/franela/goblin * github.com/google/go-github/v39 * github.com/joho/godotenv * github.com/lib/pq * github.com/moby/moby * github.com/prometheus/client_golang * github.com/tevino/abool * github.com/woodpecker-ci/togo * github.com/xanzy/go-gitlab * github.com/xeipuuv/gojsonschema * github.com/mattn/go-sqlite3
41 lines
1.2 KiB
Markdown
41 lines
1.2 KiB
Markdown
# gojsonpointer
|
|
An implementation of JSON Pointer - Go language
|
|
|
|
## Usage
|
|
jsonText := `{
|
|
"name": "Bobby B",
|
|
"occupation": {
|
|
"title" : "King",
|
|
"years" : 15,
|
|
"heir" : "Joffrey B"
|
|
}
|
|
}`
|
|
|
|
var jsonDocument map[string]interface{}
|
|
json.Unmarshal([]byte(jsonText), &jsonDocument)
|
|
|
|
//create a JSON pointer
|
|
pointerString := "/occupation/title"
|
|
pointer, _ := NewJsonPointer(pointerString)
|
|
|
|
//SET a new value for the "title" in the document
|
|
pointer.Set(jsonDocument, "Supreme Leader of Westeros")
|
|
|
|
//GET the new "title" from the document
|
|
title, _, _ := pointer.Get(jsonDocument)
|
|
fmt.Println(title) //outputs "Supreme Leader of Westeros"
|
|
|
|
//DELETE the "heir" from the document
|
|
deletePointer := NewJsonPointer("/occupation/heir")
|
|
deletePointer.Delete(jsonDocument)
|
|
|
|
b, _ := json.Marshal(jsonDocument)
|
|
fmt.Println(string(b))
|
|
//outputs `{"name":"Bobby B","occupation":{"title":"Supreme Leader of Westeros","years":15}}`
|
|
|
|
|
|
## References
|
|
https://tools.ietf.org/html/rfc6901
|
|
|
|
### Note
|
|
The 4.Evaluation part of the previous reference, starting with 'If the currently referenced value is a JSON array, the reference token MUST contain either...' is not implemented.
|