package main import ( "fmt" "github.com/keybase/go-jsonw" ) func main() { raw := []byte(`{"name":"Alice","age":25,"pets":["dog","cat"],"siblings":{"brothers":["Bob","Charlie"],"sisters":[]}}`) // Parse raw content as a JSON document. jdoc, _ := jsonw.Parse(raw) // Get the sibling brothers list as an array of strings. brothers, _ := jdoc.Get("siblings.brothers").Array() // Append a new name to the list of sisters. jdoc.Set("siblings.sisters.-1", "Eve") // Convert the document to a JSON string representation. output, _ := jdoc.MarshalJSON() fmt.Println(string(output)) }
package main import ( "fmt" "github.com/keybase/go-jsonw" ) func main() { raw := []byte(`{"foo": "bar", "nested": {"foo": "baz"}}`) jdoc, _ := jsonw.Parse(raw) // Replace the `foo` values with `qux` in both the root and nested objects. jdoc.Replace("foo", "qux") output, _ := jdoc.MarshalJSON() fmt.Println(string(output)) }In this example, we parse a JSON document from a raw content string, replace all `foo` values with `qux`, and then output the modified document as a JSON string. The package library is "github.com/keybase/go-jsonw."