jsonutil

package
v0.0.0-...-fd57926 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultJSONOptions = JSONOptions{
	Format:       FormatIndented,
	IndentPrefix: "",
	IndentSize:   2,
}

DefaultJSONOptions provides default settings for JSON formatting

Functions

func Clone

func Clone(data map[string]interface{}) (map[string]interface{}, error)

Clone creates a deep copy of a JSON map

func DeleteValue

func DeleteValue(data map[string]interface{}, path string) bool

DeleteValue removes a value from JSON using a dot-notation path

func GetValue

func GetValue(data map[string]interface{}, path string) (interface{}, bool)

GetValue retrieves a value from JSON using a dot-notation path

func MergeJSON

func MergeJSON(base, overlay map[string]interface{}) map[string]interface{}

MergeJSON merges two JSON objects, with the second one taking precedence

func PrettyPrint

func PrettyPrint(data map[string]interface{}) (string, error)

PrettyPrint converts a map to a formatted JSON string

func ReadJSON

func ReadJSON(path string) (map[string]interface{}, error)

ReadJSON reads a JSON file and unmarshals its contents into a map

func SetValue

func SetValue(data map[string]interface{}, path string, value interface{}) error

SetValue sets a value in JSON using a dot-notation path

func Validate

func Validate(path string) error

Validate checks if a file contains valid JSON

func WriteJSON

func WriteJSON(path string, data map[string]interface{}, options ...JSONOptions) error

WriteJSON writes a map to a JSON file with specified formatting

Types

type JSONFormat

type JSONFormat int

JSONFormat represents the formatting style for JSON files

const (
	// FormatStandard uses standard JSON formatting
	FormatStandard JSONFormat = iota
	// FormatIndented uses indented JSON with 2-space indentation
	FormatIndented
	// FormatMinified removes all whitespace
	FormatMinified
)

type JSONOptions

type JSONOptions struct {
	Format       JSONFormat
	IndentPrefix string
	IndentSize   int
}

JSONOptions provides configuration for JSON operations

Jump to

Keyboard shortcuts

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