Skip to content

[Repo Assist] fix: JsonValue.WriteTo uses InvariantCulture for decimal numbers#1766

Open
github-actions[bot] wants to merge 3 commits intomainfrom
repo-assist/fix-json-writeto-culture-2026-04-28-09f2ea7bfb7db127
Open

[Repo Assist] fix: JsonValue.WriteTo uses InvariantCulture for decimal numbers#1766
github-actions[bot] wants to merge 3 commits intomainfrom
repo-assist/fix-json-writeto-culture-2026-04-28-09f2ea7bfb7db127

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated pull request from Repo Assist, an AI assistant for this repository.

Root Cause

JsonValue.WriteTo serialized Number (decimal) values using w.Write(decimal), which calls Convert.ToString(value, writer.FormatProvider). For StreamWriter and other TextWriter instances, FormatProvider defaults to CultureInfo.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

  • Replace w.Write number with w.Write(number.ToString(CultureInfo.InvariantCulture)) to guarantee the correct decimal point regardless of thread culture.
  • Replace System.String(' ', indentation + plus) |> w.Write with 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 in WriteTo
  • tests/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 spaces

Test Status

Passed! - Failed: 0, Passed: 2983, Skipped: 0, Total: 2983 (net8.0)

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.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@96b9d4c39aa22359c0b38265927eadb31dcf4e2a

…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>
@dsyme dsyme marked this pull request as ready for review May 1, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant