Conversation
When the JSON parser encounters a number in exponential notation such as '3.45678E5', Decimal.TryParse with NumberStyles.Currency fails (because Currency does not include AllowExponent), so the value is stored as JsonValue.Float rather than JsonValue.Number. JsonConversions.AsDecimal previously only handled JsonValue.Number, so any field inferred as 'decimal' that received an exponential-notation value at runtime threw 'Expecting a Decimal … got …'. Fix: add a JsonValue.Float case to JsonConversions.AsDecimal that converts the float to decimal (mirroring the existing AsInteger / AsInteger64 patterns), guarding against Infinity/NaN and overflow. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
3 tasks
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dsyme
approved these changes
Feb 22, 2026
| let prov = NumericFields.ParseList(""" [{"a":123}, {"a":987}] """) | ||
| prov |> Array.map (fun v -> v.A) |> Array.sort |> should equal [|123M; 987M|] | ||
|
|
||
| // Regression test for https://github.com/fsprojects/FSharp.Data/issues/1230 |
There was a problem hiding this comment.
- Is this comment necessary?
- Why the JsonProvider is not created in-line like in the other tests?
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.
🤖 Repo Assist here — I'm an automated AI assistant for this repository.
Closes #1230Problem
When the JSON parser encounters a number in exponential notation (e.g.
3.45678E5),Decimal.TryParsewithNumberStyles.Currencyfails becauseCurrencydoes not includeAllowExponent. The value is therefore stored asJsonValue.Floatinstead ofJsonValue.Number.JsonConversions.AsDecimalpreviously only handledJsonValue.Number(andJsonValue.String), so any field inferred asdecimalthat received an exponential-notation value at runtime threw"Expecting a Decimal at '…', got …".Concrete reproduction (from #1230):
Root Cause
2.34567E5→Decimal.TryParsefails → stored asJsonValue.Float(234567.0)234567.0is an integer-valued float in Int32 range → inferred asIntegerinJsonInference.fs3.14→JsonValue.Number(3.14M)→ inferred asDecimal[Integer, Integer, Decimal]unifies toDecimal3.45678E5→JsonValue.Float(345678.0)—AsDecimalreturnsNone→ exceptionFix
Add
JsonValue.Floathandling toJsonConversions.AsDecimal, mirroring the existing pattern inAsInteger/AsInteger64:Test Status
FSharp.Data.Testspass (including new regression test)FSharp.Data.Core.Testspass (1 pre-existing network test fails due to environment proxy blocking `(www.google.com/redacted) — unrelated to this change)Warning
The following domain was blocked by the firewall during workflow execution:
www.google.com