commit | 4e3ac2762d5f479393488629ee9370b50873b3a6 | [log] [tgz] |
---|---|---|
author | xeipuuv <xeipuuv@gmail.com> | Sat Jan 27 15:07:02 2018 +1100 |
committer | GitHub <noreply@github.com> | Sat Jan 27 15:07:02 2018 +1100 |
tree | 11d9c0a36efd51cc7bc81f5285a496759302e543 | |
parent | 6fe8760cad3569743d51ddbb243b26f8456742dc [diff] | |
parent | 02e5c6a11f38f85a3f4adec8b34b690a59aec543 [diff] |
Merge pull request #3 from Aetheus/master Add Delete function
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 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.