2023-10-31 23:19:52 +00:00
|
|
|
package aid
|
|
|
|
|
2023-12-19 16:47:13 +00:00
|
|
|
import "github.com/goccy/go-json"
|
|
|
|
|
|
|
|
type JSON map[string]interface{}
|
|
|
|
|
|
|
|
func JSONFromBytes(input []byte) JSON {
|
|
|
|
var output JSON
|
|
|
|
json.Unmarshal(input, &output)
|
|
|
|
return output
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *JSON) ToBytes() []byte {
|
|
|
|
json, _ := json.Marshal(j)
|
|
|
|
return json
|
2024-01-21 17:49:14 +00:00
|
|
|
}
|
|
|
|
|
2024-02-04 15:33:38 +00:00
|
|
|
func JSONToBytes(input JSON) []byte {
|
|
|
|
json, _ := json.Marshal(input)
|
|
|
|
return json
|
|
|
|
}
|
|
|
|
|
2024-01-21 17:49:14 +00:00
|
|
|
func JSONStringify(input interface{}) string {
|
|
|
|
json, _ := json.Marshal(input)
|
|
|
|
return string(json)
|
|
|
|
}
|
|
|
|
|
|
|
|
func JSONParse(input string) interface{} {
|
|
|
|
var output interface{}
|
|
|
|
json.Unmarshal([]byte(input), &output)
|
|
|
|
return output
|
2024-03-10 18:16:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func JSONParseG[T interface{}](input string) T {
|
|
|
|
var output T
|
|
|
|
json.Unmarshal([]byte(input), &output)
|
|
|
|
return output
|
2023-12-19 16:47:13 +00:00
|
|
|
}
|