MCPcopy
hub / github.com/caddyserver/caddy / StrictUnmarshalJSON

Function StrictUnmarshalJSON

modules.go:342–350  ·  view source on GitHub ↗

StrictUnmarshalJSON is like json.Unmarshal but returns an error if any of the fields are unrecognized. Useful when decoding module configurations, where you want to be more sure they're correct.

(data []byte, v any)

Source from the content-addressed store, hash-verified

340// module configurations, where you want to be more sure they're
341// correct.
342func StrictUnmarshalJSON(data []byte, v any) error {
343 dec := json.NewDecoder(bytes.NewReader(data))
344 dec.DisallowUnknownFields()
345 err := dec.Decode(v)
346 if jsonErr, ok := err.(*json.SyntaxError); ok {
347 return fmt.Errorf("%w, at offset %d", jsonErr, jsonErr.Offset)
348 }
349 return err
350}
351
352var JSONRawMessageType = reflect.TypeFor[json.RawMessage]()
353

Callers 2

LoadModuleByIDMethod · 0.85
unsyncedDecodeAndRunFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected