go-json-path Released

go-json-path Released

go-json-path

Recently, I uses Go language to develop some applications and frameworks. Go has some standard libraries, but I found that standard configuration libraries are not provided.

I would like to use JSON format as my configuration file format, because Go supports JSON format in the standard library. However, I feel that the standard library is not useful to parse any JSON formats.

For that reason, I have developed a new open source package for Go, go-json-path. The go-json-path is a utility library to access JSON based configuration easily.

Go supports JSON format, but the decode is a bother to prepare the JSON structures [1][2]. Using the go-json-path, you can get configuration values in the specified JSON file or string by the given path like XPath. The example is bellow.

import (
    "config/jpath"
)

config, err := jpath.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

References