jsonutil

package
v0.6.17 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: MIT Imports: 7 Imported by: 25

Documentation

Overview

Package jsonutil provide some util functions for quick operate JSON data

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(bts []byte, ptr any) error

Decode json bytes to data ptr. alias of json.Unmarshal

func DecodeReader added in v0.4.3

func DecodeReader(r io.Reader, ptr any) error

DecodeReader decode JSON from io reader.

func DecodeString added in v0.5.0

func DecodeString(str string, ptr any) error

DecodeString json string to data ptr.

func Encode

func Encode(v any) ([]byte, error)

Encode data to json bytes. alias of json.Marshal

func EncodePretty added in v0.5.2

func EncodePretty(v any) ([]byte, error)

EncodePretty encode data to pretty JSON bytes.

func EncodeString added in v0.6.13

func EncodeString(v any) (string, error)

EncodeString encode data to JSON string.

func EncodeToWriter added in v0.5.0

func EncodeToWriter(v any, w io.Writer) error

EncodeToWriter encode data to json and write to writer.

func EncodeUnescapeHTML added in v0.5.0

func EncodeUnescapeHTML(v any) ([]byte, error)

EncodeUnescapeHTML data to json bytes. will close escape HTML

func IsArray added in v0.6.13

func IsArray(s string) bool

IsArray check if the string is valid JSON array.

func IsJSON added in v0.6.9

func IsJSON(s string) bool

IsJSON check if the string is valid JSON. (Note: uses json.Valid)

func IsJSONFast added in v0.6.9

func IsJSONFast(s string) bool

IsJSONFast simple and fast check input is valid JSON array or object.

func IsObject added in v0.6.13

func IsObject(s string) bool

IsObject check if the string is valid JSON object.

func Mapping added in v0.5.3

func Mapping(src, dst any) error

Mapping src data(map,struct) to dst struct use json tags.

On src, dst both is struct, equivalent to merging two structures (src should be a subset of dsc)

func MustPretty added in v0.6.13

func MustPretty(v any) string

MustPretty data to JSON string, will panic on error

func MustString added in v0.6.13

func MustString(v any) string

MustString encode data to json string, will panic on error

func Pretty

func Pretty(v any) (string, error)

Pretty JSON string and return

func ReadFile

func ReadFile(filePath string, v any) error

ReadFile Read JSON file data

func StripComments added in v0.1.3

func StripComments(src string) string

StripComments strip comments for a JSON string

func WriteFile

func WriteFile(filePath string, data any) error

WriteFile write data to JSON file

func WritePretty added in v0.6.8

func WritePretty(filePath string, data any) error

WritePretty write pretty data to JSON file

Types

This section is empty.

Jump to

Keyboard shortcuts

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