json

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2020 License: Apache-2.0 Imports: 2 Imported by: 3

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToInterface

func ToInterface(reader io.Reader) (interface{}, error)

ToInterface unmarshalls JSON reader to a "generic" interface

Example (Empty)
package main

import (
	"fmt"
	"os"
	"reflect"
	"strings"

	"github.com/VirtusLab/go-extended/pkg/json"
)

func main() {
	js := ``

	data, err := json.ToInterface(strings.NewReader(js))
	if err != nil {
		_, _ = fmt.Fprint(os.Stderr, err)
	}
	fmt.Println(data)
	fmt.Println(reflect.TypeOf(data))
	fmt.Println(reflect.ValueOf(data).Kind())

}
Output:

map[]
map[string]interface {}
map
Example (Simple)
package main

import (
	"fmt"
	"os"
	"reflect"
	"strings"

	"github.com/VirtusLab/go-extended/pkg/json"
)

func main() {
	js := `{
	"welcome":{
		"message":["Good Morning", "Hello World!"]
	}
}`

	data, err := json.ToInterface(strings.NewReader(js))
	if err != nil {
		_, _ = fmt.Fprint(os.Stderr, err)
	}
	fmt.Println(data)
	fmt.Println(reflect.TypeOf(data))
	fmt.Println(reflect.ValueOf(data).Kind())

}
Output:

map[welcome:map[message:[Good Morning Hello World!]]]
map[string]interface {}
map

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL