Skip to content

Add a FromJSONKey instance for Data.Fixed#1165

Open
VictorCMiraldo wants to merge 2 commits intohaskell:masterfrom
VictorCMiraldo:vcm/add-fromjsonkey-fixed
Open

Add a FromJSONKey instance for Data.Fixed#1165
VictorCMiraldo wants to merge 2 commits intohaskell:masterfrom
VictorCMiraldo:vcm/add-fromjsonkey-fixed

Conversation

@VictorCMiraldo
Copy link
Copy Markdown

@VictorCMiraldo VictorCMiraldo commented Apr 10, 2026

We have a ToJSONKey (Fixed a) instance:

instance HasResolution a => ToJSONKey (Fixed a) where
toJSONKey = toJSONKeyTextEnc (E.scientificText . realToFrac)

But there's no corresponding FromJSONKey (Fixed a) available. Because we have a FromJSONKey Double, it seems like this was just never added and never needed. I now have some Maps with fixed-point numbers as their keys and therefore would benefit from a FromJSONKey (Fixed a) instance. A lot of the scientific parsing functionality is internal to aeson and not exported, so I can't just add it the orphan instance on my project and call it a day, plus, if I can fix it for everyone, than it's better for everyone! :)

I tried reusing the Scientific parsing as much as possible and checked it does indeed reject large exponents in a cabal repl:

ghci> x = Object (KM.fromList [("4",String "a"),("5.32e4300",String "b")])
ghci> fromJSON x :: Result (M.Map (Fixed E12) String)
Error "found a number with exponent 4298, but it must not be greater than 1024"

Comment thread src/Data/Aeson/Types/FromJSON.hs Outdated
Comment thread tests/PropertyKeys.hs Outdated
@VictorCMiraldo VictorCMiraldo requested a review from phadej April 14, 2026 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants