jsonx

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertType

func ConvertType[T any](value interface{}) (T, error)

ConvertType converts a value to the specified type using JSON round-trip

func DeepCopy

func DeepCopy[T any](src T) (T, error)

DeepCopy performs a deep copy of an object using JSON serialization

func DeepMerge

func DeepMerge(objects ...map[string]interface{}) map[string]interface{}

DeepMerge deeply merges multiple JSON objects

func DeleteValue

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

DeleteValue deletes a value from JSON using dot notation path

func Equal

func Equal(a, b interface{}) bool

Equal compares two JSON values for equality

func Flatten

func Flatten(data map[string]interface{}) map[string]interface{}

Flatten flattens nested JSON into a flat map with dot notation keys

func FromJSON

func FromJSON[T any](jsonStr string) (T, error)

FromJSON converts JSON string to specified type

func FromMap

func FromMap[T any](data map[string]interface{}) (T, error)

FromMap converts map[string]interface{} to any struct using JSON tags

func GetArray

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

GetArray safely gets an array value from JSON data

func GetBool

func GetBool(data map[string]interface{}, key string) (bool, error)

GetBool safely gets a bool value from JSON data

func GetFloat

func GetFloat(data map[string]interface{}, key string) (float64, error)

GetFloat safely gets a float64 value from JSON data

func GetInt

func GetInt(data map[string]interface{}, key string) (int, error)

GetInt safely gets an int value from JSON data

func GetObject

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

GetObject safely gets an object value from JSON data

func GetString

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

GetString safely gets a string value from JSON data

func GetValue

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

GetValue gets a value from JSON using dot notation path

func HasPath

func HasPath(jsonData map[string]interface{}, path string) bool

HasPath checks if a path exists in JSON data

func IsValidJSON

func IsValidJSON(jsonStr string) bool

IsValidJSON checks if a string is valid JSON

func Keys

func Keys(data map[string]interface{}) []string

Keys returns all keys from a JSON object

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal marshals v to JSON with error handling

func MarshalIndent

func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error)

MarshalIndent marshals v to JSON with indentation

func MarshalPretty

func MarshalPretty(v interface{}) ([]byte, error)

MarshalPretty marshals v to pretty-printed JSON

func Merge

func Merge(objects ...map[string]interface{}) map[string]interface{}

Merge merges multiple JSON objects into one

func Minify

func Minify(jsonBytes []byte) ([]byte, error)

Minify removes unnecessary whitespace from JSON

func MinifyString

func MinifyString(jsonStr string) (string, error)

MinifyString removes unnecessary whitespace from JSON string

func SetValue

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

SetValue sets a value in JSON using dot notation path

func Size

func Size(data interface{}) int

Size returns the size of JSON data (number of keys for objects, length for arrays)

func ToJSON

func ToJSON(v interface{}) (string, error)

ToJSON converts any value to JSON string

func ToMap

func ToMap(v interface{}) (map[string]interface{}, error)

ToMap converts any struct to map[string]interface{} using JSON tags

func ToPrettyJSON

func ToPrettyJSON(v interface{}) (string, error)

ToPrettyJSON converts any value to pretty JSON string

func Unflatten

func Unflatten(flat map[string]interface{}) map[string]interface{}

Unflatten converts a flat map with dot notation keys back to nested JSON

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Unmarshal unmarshals JSON data into v

func UnmarshalFromReader

func UnmarshalFromReader(reader io.Reader, v interface{}) error

UnmarshalFromReader unmarshals JSON from io.Reader into v

func UnmarshalFromString

func UnmarshalFromString(jsonStr string, v interface{}) error

UnmarshalFromString unmarshals JSON string into v

func Values

func Values(data map[string]interface{}) []interface{}

Values returns all values from a JSON object

Types

This section is empty.

Jump to

Keyboard shortcuts

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