How to parse a JSON object?

The integer is more than 2^53 - 1 maxSafeInteger, so it cannot be represented precisely in Elm or JavaScript. 4652007308841189000 is its float representation in JavaScript, losing the precision of the last 3 digits.

Try pasting the number in your browser JavaScript console, you will get the same result.

If you cannot change the JSON format (for example using a string instead of an integer for such numbers), you can either modify the string before decoding it, or use a custom parser, for example using allenap/elm-json-decode-broken, decoding numbers as strings (ex: https://ellie-app.com/7Kmcsgq79yqa1).

3 Likes