File: json.go

package info (click to toggle)
golang-github-knadh-koanf 2.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 808 kB
  • sloc: sh: 31; makefile: 14
file content (28 lines) | stat: -rw-r--r-- 632 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Package json implements a koanf.Parser that parses JSON bytes as conf maps.
package json

import (
	"encoding/json"
)

// JSON implements a JSON parser.
type JSON struct{}

// Parser returns a JSON Parser.
func Parser() *JSON {
	return &JSON{}
}

// Unmarshal parses the given JSON bytes.
func (p *JSON) Unmarshal(b []byte) (map[string]interface{}, error) {
	var out map[string]interface{}
	if err := json.Unmarshal(b, &out); err != nil {
		return nil, err
	}
	return out, nil
}

// Marshal marshals the given config map to JSON bytes.
func (p *JSON) Marshal(o map[string]interface{}) ([]byte, error) {
	return json.Marshal(o)
}