Standard library / log/slog

slog.Level.UnmarshalJSON()

Parse a JSON string as a severity level. Expected stdout: 'WARN\n'.

Formal Syntax & Structure

go syntaxgo
func (l *Level) UnmarshalJSON(data []byte) error

Parameters & Attributes

NameTypeDescription
data[]byteInput to the operation as described above.

Return Value

error

Parse a JSON string as a severity level.

Working Example

Example Snippetgo
package main
import (  "fmt"  "log/slog")
func check(e error) {  if e != nil {    panic(e)  }}
func main() { var l slog.Level; check(l.UnmarshalJSON([]byte(`"WARN"`))); fmt.Println(l) }
Go Reference