Json
Fork of golang's encoding/json: now with more validation and error context
Install / Use
/learn @koki/JsonREADME
Koki's JSON library
It's a fork that makes encoding/json better for users.
Features
-
Annotates decoder errors with the path (e.g.
$.pod.container.0.env) where the error occurred. The golang built-in implementation doesn't contextualize errors, so it's hard to track down where they came from. -
Check for extraneous fields in your JSON, which is useful for detecting misspelled keys and other typos.
-
omitemptyactually omits zero-valued structs.
How to use it
github.com/koki/json is a drop-in replacement for encoding/json. The decoder implementation is different, but the library API remains unchanged. Use this package's json.Unmarshal if you want paths for your decoder errors. Use json.Marshal if you want to omit zero-valued structs.
// Deserialize
foo := Foo{}
err := json.Unmarshal(data, &foo)
...
// Serialize
bar := Bar{}
data, err := json.Marshal(bar)
...
github.com/koki/json/jsonutil is a brand-new package. Use jsonutil.ExtraneousFieldPaths to get a list of paths that weren't decoded into your Go object. i.e. potential typos.
// 1. Parse.
obj := make(map[string]interface{})
parsedObj := Foo{}
err := json.Unmarshal(data, &obj)
...
err = jsonutil.UnmarshalMap(obj, &parsedObj)
...
// 2. Check for unparsed fields--potential typos.
extraneousPaths, err := jsonutil.ExtraneousFieldPaths(obj, parsedObj)
...
if len(extraneousPaths) > 0 {
return nil, &jsonutil.ExtraneousFieldsError{Paths: extraneousPaths}
}
...
Related Skills
node-connect
354.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
xurl
354.2kA CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.
frontend-design
112.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
354.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
