go-json-path

go-json-path is a utility library to access JSON based configuration easily. Go language supports JSON format in the standard library. However, I feel that the standard library is not useful to parse any JSON formats [1] [2].

For that reason, I have developed the open source package to access JSON based configuration easily. Using go-json-path, you can get configuration values in the specified JSON file or string by the given path like Path. The example is bellow.

import (
    "config/jpath"
)

config, err := xjson.NewConfig()
if err != nil {
    t.Error(err)
}

err = config.ParseFromFile("/etc/profile.conf")
if err != nil {
    t.Error(err)
}

name, err := config.GetKeyStringByPath("/organizer/name")
if err != nil {
    t.Error(err)
}

age, err := config.GetKeyStringByPath("/organizer/age")
if err != nil {
    t.Error(err)
}

The configuration file format is based on JSON as the following.

#
#  /etc/profile.conf
#

{
    "organizer": {
        "name": "John Smith",
        "age": 33
    }
}

Repository

Documents

Please check the godoc of config/jpath as the following.

godoc -http=:6060

References