Skip to content

JsonSchemaExporter interaction with byte[] #130869

Closed

Description

@Youssef1313

Description

Schema for byte[] should produce "contentEncoding": "base64"

https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-8.3

I think this is how STJ handles byte[] when serializing/deserializing.

Reproduction Steps

var x = new JsonSerializerOptions();
x.WriteIndented = true;
x.TypeInfoResolver = JsonSerializerOptions.Default.TypeInfoResolver;

Console.WriteLine(JsonSchemaExporter.GetJsonSchemaAsNode(x, typeof(byte[])).ToJsonString(x));

Expected behavior

contentEncoding is emitted and set to base64.

Actual behavior

{
  "type": [
    "string",
    "null"
  ]
}

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Activity

  1. added
    untriaged
    on Jul 16, 2026
  2. dotnet-policy-service commented on Jul 16, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-text-json
    See info in area-owners.md if you want to be subscribed.

  3. eiriktsarpalis commented on Jul 16, 2026

    @eiriktsarpalis
    Member

    We haven't been applying the contentEncoding keyword elsewhere. Are there other primitive types (e.g. DateTimeOffset, Guid, Uri, etc) that should also apply it?

  4. Youssef1313 commented on Jul 16, 2026

    @Youssef1313
    MemberAuthor

    Apart from byte[], Memory<byte>, and ReadOnlyMemory<byte>, I'm not aware of anything else that needs special contentEncoding handling. I think date/time, guid, uri all end up in format which is already handled per https://json-schema.org/draft/2020-12/json-schema-validation#section-7.3

  5. eiriktsarpalis commented on Jul 16, 2026

    @eiriktsarpalis
    Member

    Ok -- care to file a PR?

  6. Youssef1313 commented on Jul 16, 2026

    @Youssef1313
    MemberAuthor

    Sure, assigned to Copilot with instructions. I think the right place to do this is by overriding CreateSchema in the relevant json converters.

  7. removed
    untriaged
    on Jul 27, 2026
  8. locked and limited conversation to collaborators on Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions