Automatic promotion of filed int values to float? #4254
Unanswered
tksharpless
asked this question in
Q&A
Replies: 2 comments 1 reply
-
No, unfortunately not. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Are you saying there are no options for type coercion or automatic
promotion? I hope you will consider offering such options in future
releases, as they could be really useful. For now, I will write
conditional code that checks the numeric type, as you suggest; but I think
you should reconsider whether runtime type checking really adds any value.
Regards,
Thomas
…On Fri, Dec 29, 2023 at 2:11 PM Niels Lohmann ***@***.***> wrote:
You would need to use is_number_float (
https://json.nlohmann.me/api/basic_json/is_number_float/) and such to
check first.
—
Reply to this email directly, view it on GitHub
<#4254 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACBEZZUYYLJ4WVUJFQO3FUDYL4IVFAVCNFSM6AAAAABBG4XTTSVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM3TSNZVGA4DK>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a lot of Json files where all zero values appear as simply '0', and some float values that happen to be integers are printed as such. I know which names are really integers and which really floats, and would like to parse them into variables of appropriate types, assigning a default value when the name is absent.
The value() function seems good for that but unfortunately, when the filed number looks like an int and the default value is float, it fails with a runtime type exception.
Is there an easy workaround?
Beta Was this translation helpful? Give feedback.
All reactions