Skip to content

parse json string hommization, operate json string without define struct to decode

Notifications You must be signed in to change notification settings

PavelHank/hjson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

hjson

parse json string hommization for golang. You can fetch any value by key path.

How To Install?

> go get github.com/PavelHank/hjson

Example

We can achieve any json node by key path, there are some example to explain how to use the library. Below example depend the facade json data:

{
    "name": "Pavel Hank",
    "birthday": 1269003023,
    "favorite_sports": [
        "Basketball",
        "Football",
        "Badminton"
    ],
    "preferences":{
        "eat": [
            "rice",
            "noodles",
            "milk"
        ],
        "sports":{
             "Basketball":"crazy",
            "Football":"watch games some time",
            "Badminton":"beloved"
        }
    },
    "is_student": false,
    "is_programmer":true,
    "bio":"poor life, and poor soul, just live in this world like a wanderer, no one pays attention, no one knows",
    "deposit": 262.62
}

GetString

import "github.com/PavelHank/hjson"

func main(){
    // GetString by key.
    fmt.Println(hjson.GetString([]byte(json), "name"))
    // Output:
    // Pavel Hank <nil>

    // GetString by key path in deepper level.
    fmt.Println(hjson.GetString([]byte(json), "preferences.sports.Basketball"))
    // Output:
    // crazy <nil>

    // GetString from json array
    fmt.Println(hjson.GetString([]byte(json), "preferences.eat.$0"))
    // Output:
    // rice <nil>
}

GetInt/GetFloat/GetBool

used it like GetString function.

Bug Report

report any bug with new issues or hit my email: pavelhank@outlook.com

About

parse json string hommization, operate json string without define struct to decode

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages