commit | e0d451ea52c8e65cea3e82eb35968abcec6e524a | [log] [tgz] |
---|---|---|
author | Adrian <adrianhyk@gmail.com> | Sun Oct 29 21:12:17 2017 +0800 |
committer | Adrian <adrianhyk@gmail.com> | Sun Oct 29 21:12:17 2017 +0800 |
tree | 8a288b3dd1a27e987c9078a295c94372e8a426b6 | |
parent | bd4bc22e6f0ba5481ecaffafa9806a60da8e3fe0 [diff] |
use the same function signature as "Set"; Kind data is probably not used when deleting
An implementation of JSON Pointer - Go language
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 (only works on maps for now, not arrays) 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}}`
http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-07
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.