Skip to content

Instance Method

encode(to:)

This claim can take either singular or plural form in JSON, with the singular being overwhelmingly more common, so when there is only one value, ensure it is encoded as a scalar, not an array.
func encode(to encoder: any Encoder) throws

Discussion

Note

As in decoding, the implementation takes a conservative approach with regards to the importance of ordering and the handling of duplicate values by simply encoding what’s there without further analysis or filtering.

Warning

If the claim has zero values, this implementation will encode an inefficient zero-element representation. See the notes regarding this on init(from decoder:) above.