Skip to content

JsonSchemaExporter doesn't respect IgnoreReadOnlyProperties/IgnoreReadOnlyFields #131632

Description

@Youssef1313

Description

The IgnoreReadOnlyProperties and IgnoreReadOnlyFields options are not taken into consideration by the JsonSchemaExporter today.

A property that is never serialized or deserialized is still emitting as part of the JSON schema.

Reproduction Steps

using System;
using System.Text.Json;
using System.Text.Json.Schema;

var options = new JsonSerializerOptions(JsonSerializerOptions.Default)
{
    IgnoreReadOnlyProperties = true,
    IgnoreReadOnlyFields = true,
};

Console.WriteLine("Serialized object:");
Console.WriteLine(JsonSerializer.Serialize(new C(), options));

Console.WriteLine();
Console.WriteLine("======");
Console.WriteLine();

Console.WriteLine("Json schema:");
Console.WriteLine(options.GetJsonSchemaAsNode(typeof(C)));


class C
{
    public string S => "Hello";
}

Expected behavior

Output is:

Serialized object:
{}

======

Json schema:
{
  "type": [
    "object",
    "null"
  ]
}

Actual behavior

Output is:

Serialized object:
{}

======

Json schema:
{
  "type": [
    "object",
    "null"
  ],
  "properties": {
    "S": {
      "type": [
        "string",
        "null"
      ]
    }
  }
}

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Activity

  1. added
    untriaged
    on Jul 31, 2026
  2. dotnet-policy-service commented on Jul 31, 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. added theissue type on Jul 31, 2026
  4. removed
    untriaged
    on Aug 11, 2026
  5. added this to the 11.0.0 milestone on Aug 11, 2026
  6. modified the milestones: 11.0.0, 12.0.0 on Aug 27, 2026
  7. added a commit that references this issue on Nov 5, 2026
    ebc3468
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions