Skip to content

gofika/jsonutil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

codecov Build Status go.dev Go Report Card Licenses

jsonutil

golang json utils for common use

Basic Usage

Installation

To get the package, execute:

go get github.com/gofika/jsonutil

Example

package main

import (
	"fmt"
	"github.com/gofika/jsonutil"
)

type Foo struct {
	Name  string `json:"name"`
	Value int    `json:"value"`
}

func main() {
	foo := &Foo{
		Name:  "Jason",
		Value: 100,
	}
	name := "foo.json"
	// write struct to file
	err := jsonutil.WriteFile(name, foo)
	if err != nil {
		fmt.Printf("WriteFile failed. err: %s\n", err.Error())
		return
	}
	// read struct from file
	bar, err = jsonutil.ReadFile[Foo](name)
	if err != nil {
		fmt.Printf("ReadFile failed. err: %s\n", err.Error())
		return
	}
	fmt.Printf("bar.Name: %s\n", bar.Name)
	fmt.Printf("bar.Value: %d\n", bar.Value)
}

About

golang json utils for common use

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages