Skip to content

proposal: encoding/json/jsontext: add Kind.IsValid #75431

@antoniszymanski

Description

@antoniszymanski

Proposal Details

This is a sub-issue of the "encoding/json/v2" proposal (#71497).

I propose adding the following to the encoding/json/jsontext (Switch statement generates longer assembly).

func (k Kind) IsValid() bool {
	return k == 'n' || k == 'f' || k == 't' || k == '"' || k == '0' || k == '{' || k == '}' || k == '[' || k == ']'
}

Rationale

This provides a reliable way to determine whether Kind is valid, because as I learned, this is incorrect.

func (k Kind) IsValid() bool {
	return k != 0
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposal

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions