Skip to main content

Parsing Results Examples

Under the hood Zog follows the Parsing Execution Structure and does a bunch of things under the hood to make sure your data is parsed correctly. Such as checking for zero values, coercing types, etc...

Some of this might not be obvious so here is a summary table that breaksdown expected results of calling schema.Parse() on various inputs:

Schema TypeDataDestRequired Error (Zero Value)Coercion Error
Bool()truetruenono
Bool()falsefalsenono
Bool()nilfalseyesyes
Bool()""falseyesyes
Bool()" "falseyesyes
Bool()ontruenono
Bool()offfalsenono
Bool()["true", "t", "T", "True", "TRUE"]truenono
Bool()["false", "f", "F", "FALSE", "False"]falsenono
Bool()testfalsenoyes
Bool()1truenono
Bool()0falsenono
Bool()123falsenoyes
String()""""yesno
String()" """yesno
String()nil""yesyes
String()any valuefmt.Sprintf("%v", value)nono
Int()00nono
Int()1010nono
Int()nil0yesyes
Int()""0yesyes
Int()" "0yesyes
Int()any stringstrconv.Atoi(str)nodepends
Int()6.296nono
Int()true1nono
Int()false0nono
Float()1.211.21nono
Float()00nono
Float()nil0yesyes
Float()""0yesyes
Float()" "0yesyes
Float()any stringstrconv.ParseFloat(str)nodepends
Float()11nono
Time()time.Time{}time.Time{}nono
Time()time.Now()time.Now()nono
Time()niltime.Time{}yesyes
Time()""time.Time{}yesyes
Time()" "time.Time{}yesyes
Time()unix_timestamp_mstime.Unix(unix, 0)nono
Time()any stringtime.Parse(format, str)nodepends
Slice()[1][1]nono
Slice()[][]nono
Slice()nil[null]yesno (error will show in the appropriate schema if any)
Slice()""[""]yesno (error will show in the appropriate schema if any)
Slice()" "[" "]yesno (error will show in the appropriate schema if any)
Slice()any_value[value]dependsno (error will show in the appropriate schema if any)