02_quick_start.md
May 31, 2025 ยท View on GitHub
Quick Start
Prev Page | Contents | Next Page
To create a complex JSON object as follows:
{
"obj": {
"obj": {
"obj": {
"str": "Hello, JSON!"
}
}
}
}
Just three lines with jsonvalue:
v := jsonvalue.NewObject()
v.Set("Hello, JSON").At("obj", "obj", "obj", "str")
fmt.Println(v.MustMarshalString())
Output: {"obj":{"obj":{"obj":{"str":"Hello, JSON!"}}}
On the other hand, if we want to fetch a single value from the JSON bytes above, it is also easy:
const raw = `{"obj": {"obj": {"obj": {"str": "Hello, JSON!"}}}}`
s := jsonvalue.MustUnmarshalString(raw).MustGet("obj", "obj", "obj", "str").String()
fmt.Println(s)
Output: Hello, JSON!