xing393939 / jsonobject

Easy JSON parser for Go. No custom structs, no code generation, no reflection.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build codecov Go Reference

Easy JSON parser for Go. No custom structs, no code generation, no reflection.

Installing

go get github.com/xing393939/jsonobject

Usage

jsonContent := `{
    "isMaster": false, 
    "metadata": {
        "name": "oracle"
    },
    "tags": ["db", "sql"]
}`
jo := jsonobject.NewJsonObject(jsonContent)
println(jo.GetBool("isMaster"))
println(jo.GetJsonObject("metadata").GetString("name"))
joArr := jo.GetJsonObjectSlice("tags")
for _, joRow := range joArr {
    println(joRow.GetString())
}

jsonContent = `[{"name":"John", "score":100}, {"name":"Tom", "score":200}]`
jo = jsonobject.NewJsonObject(jsonContent)
joArr = jo.GetJsonObjectSlice()
for _, joRow := range joArr {
    println(joRow.GetString("name"), joRow.GetInt("score"))
}

About

Easy JSON parser for Go. No custom structs, no code generation, no reflection.

License:MIT License


Languages

Language:Go 100.0%