kpjson

package
Version: v0.8.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2019 License: MIT Imports: 5 Imported by: 0

README

JSON Parser

JSON parser parses a JSON file to a map[string]interface{} and then traverses the map and adds values into the config store flattening the JSON using dot notation for keys.

Ex:

{
    "foo": "bar",
    "nested": {
        "firstName": "john",
        "lastName": "doe",
        "list": [
            1,
            2,
        ]
    }
}

Will add the following key/value to the config

"foo" => "bar"
"nested.firstName" => "john"
"nested.lastName" => "doe"
"nested.list" => []int{1,2}

Usage

err := kpjson.Parser.Parse(strings.NewReader(`{"foo":"bar"}`), konfig.Values{})

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Parser = parser.Func(func(r io.Reader, s konfig.Values) error {
	// unmarshal the JSON into  map[string]interface{}
	var dec = json.NewDecoder(r)

	var d = make(map[string]interface{})
	var err = dec.Decode(&d)
	if err != nil {
		return err
	}

	kpmap.PopFlatten(d, s)

	return nil
})

Parser parses the given json io.Reader and adds values in dot.path notation into the konfig.Store

Functions

This section is empty.

Types

This section is empty.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL