Download common/json.go from AZILS/new-api: direct link, hf CLI and curl.
- Browser
- Download file 762 Bytes
-
https://huggingface.co/spaces/AZILS/new-api/resolve/main/common/json.go
- Command line
-
hf download hf://spaces/AZILS/new-api/common/json.go
-
curl -L -o json.go https://huggingface.co/spaces/AZILS/new-api/resolve/main/common/json.go
762 Bytes
| package common | |
| import ( | |
| "bytes" | |
| "encoding/json" | |
| "io" | |
| ) | |
| func Unmarshal(data []byte, v any) error { | |
| return json.Unmarshal(data, v) | |
| } | |
| func UnmarshalJsonStr(data string, v any) error { | |
| return json.Unmarshal(StringToByteSlice(data), v) | |
| } | |
| func DecodeJson(reader io.Reader, v any) error { | |
| return json.NewDecoder(reader).Decode(v) | |
| } | |
| func Marshal(v any) ([]byte, error) { | |
| return json.Marshal(v) | |
| } | |
| func GetJsonType(data json.RawMessage) string { | |
| data = bytes.TrimSpace(data) | |
| if len(data) == 0 { | |
| return "unknown" | |
| } | |
| firstChar := bytes.TrimSpace(data)[0] | |
| switch firstChar { | |
| case '{': | |
| return "object" | |
| case '[': | |
| return "array" | |
| case '"': | |
| return "string" | |
| case 't', 'f': | |
| return "boolean" | |
| case 'n': | |
| return "null" | |
| default: | |
| return "number" | |
| } | |
| } | |