json

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package json has some utilities for JSON codec

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSONToStruct

func JSONToStruct(interFace interface{}, jsonData string) error

JSONToStruct convert JSON to a Struct The struct must have json tags

:param interFace: A pointer to a variable of the struct data with json tags
:param jsonData: The JSON data

Example

type NTP struct {
	NTPServersData struct {
		SourceInterface string `yaml:"source_interface" json:"source_interface" xml:"source_interface"`
		NTPServerKey    []struct {
			IPv4Host string `yaml:"ipv4_host" json:"ipv4_host" xml:"ipv4_host"`
			Priority bool   `yaml:"priority" json:"priority" xml:"priority"`
		} `yaml:"ntp_servers" json:"ntp_servers" xml:"ntp_servers"`
	} `yaml:"ntp" json:"ntp" xml:"ntp"`
}

var a NTP

err := json.JSONToStruct(&a, ntpJson)
if err != nil {
	log.Fatal(err)
}

fmt.Println(a)

func StructToJSON

func StructToJSON(interFace interface{}) (jsonData string, err error)

StructToJSON convert struct to JSON The struct must have json tags

:param interFace: The struct data with json tags

Example

var a NTP

thing, err := xml.StructToJSON(a)

fmt.Println(thing)

Types

This section is empty.

Jump to

Keyboard shortcuts

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