Standard library / log/slog
slog.Level.MarshalJSON()
Encode a level as a JSON string. Expected stdout: '"WARN"\n'.
Formal Syntax & Structure
go syntaxgo
func (l Level) MarshalJSON() ([]byte, error)Return Value
([]byte, error)
Encode a level as a JSON string.
Working Example
Example Snippetgo
package main
import ( "fmt" "log/slog")
func check(e error) { if e != nil { panic(e) }}
func main() { b, e := slog.LevelWarn.MarshalJSON(); check(e); fmt.Println(string(b)) }