New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ConvertTo-Json: Serialize BigInteger as a number #21000
Conversation
Serializes a BigInteger value as a raw JSON number rather than the object's properties which does not contain the BigInteger value.
| @@ -519,6 +520,10 @@ private static object ProcessValue(object obj, int currentDepth, in ConvertToJso | |||
| { | |||
| rv = jObject.ToObject<Dictionary<object, object>>(); | |||
| } | |||
| else if (obj is BigInteger bi) | |||
| { | |||
| rv = new JRaw(bi.ToString(NumberFormatInfo.InvariantInfo)); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need JRaw?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the value isn’t quoted and is a literal numeric value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should use string if we agree with #20999 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I don't see why we should but I'll leave it up to the WG decision in the end.
If they do decide to quote BigIntegers so then it should only happen if the value is larger than the Javascript precision value. I would have to say I really don’t think it’s a good idea as it complicates the cmdlet even more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out it isn't needed we just need to ensure the value is the BigInteger itself and we don't do PowerShell's property enumerator.
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
|
The WG agrees that the same reasoning in #20999 (comment) applies here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks @jborean93!
|
📣 Hey @jborean93, how did we do? We would love to hear your feedback with the link below! 🗣️ 🔗 https://aka.ms/PSRepoFeedback |


PR Summary
Serializes a BigInteger value as a raw JSON number rather than the object's properties which does not contain the BigInteger value.
This is technically a breaking change, I went ahead with the PR anyway to see if it was actually possible to do (it is). Waiting for the triage outcome of #20989 (comment) to see if this breaking change is ok or not.
PR Context
Fixes: #20989
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).