Skip to content

Does JsonSchemaExporter handle decimal pattern correctly? #130868

Description

@Youssef1313

Description

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

var x = new JsonSerializerOptions();
x.WriteIndented = true;
x.TypeInfoResolver = JsonSerializerOptions.Default.TypeInfoResolver;
x.NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString;
x.Converters.Add(new JsonStringEnumConverter());

Console.WriteLine(JsonSchemaExporter.GetJsonSchemaAsNode(x, typeof(decimal)).ToJsonString(x));

Console.WriteLine(JsonSerializer.Deserialize<decimal>("\"1E4\"", x));

Reproduction Steps

See above.

The deserialization of "1E4" works and prints 10000, but the pattern produced doesn't seem to handle the exponent syntax.

The produced schema today is:

{
  "type": [
    "string",
    "number"
  ],
  "pattern": "^-?(?:0|[1-9]\\d*)(?:\\.\\d\u002B)?$"
}

Expected behavior

Pattern should allow 1E4

Actual behavior

It doesn't

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Activity

  1. added
    untriaged
    on Jul 16, 2026
  2. Youssef1313 commented on Jul 16, 2026

    @Youssef1313
    MemberAuthor
  3. 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.

  4. eiriktsarpalis commented on Jul 16, 2026

    @eiriktsarpalis
    Member

    The pattern keyword was added as a rudimentary gating mechanism for string encoded numbers, but it did not account for exponential notation. Would you like to submit a PR extending the regex?

  5. added a commit that references this issue on Jul 16, 2026
    41344e4
  6. added and removed
    untriaged
    on Aug 16, 2026
  7. added this to the 11.0.0 milestone on Aug 16, 2026
  8. modified the milestones: 11.0.0, 12.0.0 on Aug 27, 2026
  9. added a commit that references this issue on Nov 4, 2026
    f239bc8
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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions