Skip to content
/ tojson Public

tojson package allows the user to save/load data of go structs into/from a file in json format.

License

Notifications You must be signed in to change notification settings

dns-gh/tojson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

tojson package

Go Report Card

[GoDoc] (https://godoc.org/github.com/dns-gh/tojson)

Simple wrapper over the encoding/json package to save and load data into a file in json format

Motivation

Simplify a little bit the code for other projects.

Installation

  • It requires Go language of course. You can set it up by downloading it here: https://golang.org/dl/
  • Install it here C:/Go.
  • Set your GOPATH, GOROOT and PATH environment variables:
export GOROOT=C:/Go
export GOPATH=WORKING_DIR
export PATH=C:/Go/bin:${PATH}
  • Download and install the package:
@working_dir $ go get github.com/dns-gh/tojson/...
@working_dir $ go install github.com/dns-gh/tojson

Usage

package main

import "github.com/dns-gh/tojson"

type equipment struct {
	Weapon string `json:"weapon"`
	Shield string `json:"shield"`
}

func main() {
	oldEquipment := &equipment{
		Weapon: "sword",
		Shield: "wooden",
	}
	file := "equipment.json"
	tojson.Save(file, oldEquipment)
	newEquipement := &equipment{}
	tojson.Load(file, newEquipement)
}

Tests

@working_dir $ go test -v github.com/dns-gh/tojson
=== RUN   TestSaveLoadJSON
--- PASS: TestSaveLoadJSON (0.00s)
PASS
ok      tojson  0.055s

LICENSE

See included LICENSE file.

About

tojson package allows the user to save/load data of go structs into/from a file in json format.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages