...

Text file src/github.com/xeipuuv/gojsonpointer/README.md

Documentation: github.com/xeipuuv/gojsonpointer

     1# gojsonpointer
     2An implementation of JSON Pointer - Go language
     3
     4## Usage
     5	jsonText := `{
     6		"name": "Bobby B",
     7		"occupation": {
     8			"title" : "King",
     9			"years" : 15,
    10			"heir" : "Joffrey B"			
    11		}
    12	}`
    13	
    14    var jsonDocument map[string]interface{}
    15    json.Unmarshal([]byte(jsonText), &jsonDocument)
    16    
    17    //create a JSON pointer
    18    pointerString := "/occupation/title"
    19    pointer, _ := NewJsonPointer(pointerString)
    20    
    21    //SET a new value for the "title" in the document     
    22    pointer.Set(jsonDocument, "Supreme Leader of Westeros")
    23    
    24    //GET the new "title" from the document
    25    title, _, _ := pointer.Get(jsonDocument)
    26    fmt.Println(title) //outputs "Supreme Leader of Westeros"
    27    
    28    //DELETE the "heir" from the document
    29    deletePointer := NewJsonPointer("/occupation/heir")
    30    deletePointer.Delete(jsonDocument)
    31    
    32    b, _ := json.Marshal(jsonDocument)
    33    fmt.Println(string(b))
    34    //outputs `{"name":"Bobby B","occupation":{"title":"Supreme Leader of Westeros","years":15}}`
    35
    36
    37## References
    38https://tools.ietf.org/html/rfc6901
    39
    40### Note
    41The 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.

View as plain text