jsonutil

package
v12.41.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package jsonutil provides methods for working with JSON data

Index

Examples

Constants

This section is empty.

Variables

View Source
var GzipLevel = gzip.BestSpeed

GzipLevel is default Gzip compression level

Functions

func Read

func Read(file string, v interface{}) error

Read reads and decode JSON file

Example
var data = make(map[string]int)

err := Read("/path/to/file.json", data)

if err != nil {
	fmt.Printf("Error: %v\n", err)
}
Output:

func ReadGz

func ReadGz(file string, v interface{}) error

ReadGz reads and decode gzipped JSON file

Example
var data = make(map[string]int)

err := ReadGz("/path/to/file.gz", data)

if err != nil {
	fmt.Printf("Error: %v\n", err)
}
Output:

func Write

func Write(file string, v interface{}, perms ...os.FileMode) error

Write encodes data to JSON and save it to file

Example
var data = make(map[string]int)

data["john"] = 100
data["bob"] = 300

err := Write("/path/to/file.json", data, 0600)

if err != nil {
	fmt.Printf("Error: %v\n", err)
}
Output:

func WriteGz

func WriteGz(file string, v interface{}, perms ...os.FileMode) error

Write encodes data to gzipped JSON and save it to file

Example
var data = make(map[string]int)

data["john"] = 100
data["bob"] = 300

err := WriteGz("/path/to/file.gz", data, 0600)

if err != nil {
	fmt.Printf("Error: %v\n", err)
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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