Skip to content

encoding/json/v2: documentation doesn't specify that format option has to come last #77547

Description

@dominikh

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.NeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions