1mb

build with

gopantic

JSON and YAML into validated structs

get gopantic docs

Parse, convert and validate in one call. ParseInto[User](raw) takes JSON or YAML and returns a User, with every problem reported at once.

A value converts when nothing is lost: "42" into an int gives 42. 4.7 into an int is an error.

Seven built-in rules go in validate tags. Custom rules register beside them, including ones that read other fields. One dependency, yaml.v3.

The format is detected from the input. A single line like name: Alice is read as JSON, so ParseIntoWithFormat names it.

why it exists

gopantic reads input a program doesn't control into a Go struct: API payloads where numbers arrive as strings, config files that may be JSON or YAML.

The API is Pydantic-inspired: the rules sit in the struct's tags, so they can't drift from the type. What comes back is the value the input meant, or an error.

what it taught

Coercion exists to accept input that means something obvious, and it stops where the meaning stops. 300 can't fit an int8. v1.4.1 returned 44 with no error.

v1.5.0 refuses it, so input v1.4.1 accepted can fail.

get gopantic

related

all work