Running
package main
import (
"encoding/json/v2"
"fmt"
)
type T struct {
Foo string `json:"foo,format:RFC3339,omitempty"`
}
func main() {
t := T{Foo: "hi"}
_, err := json.Marshal(t)
fmt.Println(err)
}
prints
json: cannot marshal from Go main.T: Go struct field Foo has `format` tag option that was not specified last
But to the best of my reading skills, the documentation doesn't mention this requirement. This can be especially confusing because there isn't currently a discernible reason for this restriction (it constitutes future-proofing, see go-json-experiment/json@2225d15, but the average user won't know that.)
Running
prints
But to the best of my reading skills, the documentation doesn't mention this requirement. This can be especially confusing because there isn't currently a discernible reason for this restriction (it constitutes future-proofing, see go-json-experiment/json@2225d15, but the average user won't know that.)