[Repo Assist] fix: JsonValue.WriteTo uses InvariantCulture for decimal numbers#1766
Open
github-actions[bot] wants to merge 3 commits intomainfrom
Open
Conversation
…rs; avoid indentation string alloc
- Number decimal values are now serialized with CultureInfo.InvariantCulture
to prevent invalid JSON output (e.g. '1,5' instead of '1.5') when
WriteTo is called with a TextWriter configured with a non-English culture.
TextWriter.Write(decimal) uses the writer's FormatProvider by default,
which for StreamWriter and other writers is CultureInfo.CurrentCulture.
- Replace System.String(' ', n) per indentation level with a loop writing
individual space chars to avoid allocating one string per newLine call
during pretty-printing.
- Add three regression tests covering the culture-invariant serialization
and custom indentation behaviour.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Apr 29, 2026
…-28-09f2ea7bfb7db127
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated pull request from Repo Assist, an AI assistant for this repository.
Root Cause
JsonValue.WriteToserializedNumber(decimal) values usingw.Write(decimal), which callsConvert.ToString(value, writer.FormatProvider). ForStreamWriterand otherTextWriterinstances,FormatProviderdefaults toCultureInfo.CurrentCulture. In cultures that use,as the decimal separator (e.g.de-DE,fr-FR), this produces invalid JSON like{"price":1,5}instead of{"price":1.5}.Fix
w.Write numberwithw.Write(number.ToString(CultureInfo.InvariantCulture))to guarantee the correct decimal point regardless of thread culture.System.String(' ', indentation + plus) |> w.Writewith a direct loop writing individual space characters, eliminating one string allocation per newline in pretty-print mode.Changes
src/FSharp.Data.Json.Core/JsonValue.fs— two-line fix inWriteTotests/FSharp.Data.Core.Tests/JsonValue.fs— three new regression tests:JsonValue WriteTo serializes decimals using InvariantCulture regardless of thread culture(de-DE)JsonValue ToString serializes decimal array using InvariantCulture(fr-FR)JsonValue WriteTo indentation uses correct number of spacesTest Status
Pre-existing infrastructure warning (OpenTelemetry.Api 1.15.0 vulnerability via NuGet audit) suppressed with
-p:NuGetAudit=false; unrelated to this change, tracked in PR #1762.