-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
JsonElement.ToString() returns invalid json: "True"/"False" #107998
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis |
Duplicate of #42502 (yet the issue persists).
If you serialize the element, you get what you expect, but I think that's overkill. |
It does not spit the original Json text it was given, it returns I'm honestly surprised this is still an issue 4 years after being pointed out. This is a super easy fix and it would comply with the json spec. I don't see any reason to keep the capital values; can you help explain the reason for not fixing? "Its called out in the documentation" doesn't really explain why this bug has persisted. |
Another thing I noticed is the JsonElement.ToString() outputs correct json syntax for objects and arrays. This makes things even more confusing that the boolean outputs incorrect json. |
@jelliott-MS It's not just boolean values, JsonElement.ToString() doesn't output the correct json syntax for json string values and json null either. |
I find this behaviour to be unintuitive as well, but it seems to be very much by-design behavior. It would be a breaking change to alter now. |
@elgonzo I'm aware of null, what does the toString() output for valuekind of string that isn't valid? |
@eiriktsarpalis Unfortunately I think you're correct about the breaking change. Thanks anyways, we have a workaround implemented
|
@jelliott-MS not including the surrounding double-quotes as required by the json syntax nor escaping back-slash and double-quote characters in the value as also required by the json syntax (https://dotnetfiddle.net/cR1O17). If you don't like ToString() returning (As a side note, JsonElement.ToString() using the string representation |
How about using |
Are you suggesting GetRawText for the fallthrough or to use in place of the original ToString call? Will GetRawText return the correct json data for all types? |
|
Closing as duplicate of #42502. |
Description
The
JsonElement.ToString()
method returnsBoolean.TrueString
andBoolean.FalseString
if theJsonValueKind
is True/False.https://learn.microsoft.com/en-us/dotnet/api/system.text.json.jsonelement.tostring?view=net-8.0#remarks
Boolean.TrueString
andBoolean.FalseString
evaluate to"True"
and"False"
respectivelyhttps://learn.microsoft.com/en-us/dotnet/api/system.boolean.truestring?view=net-8.0#remarks
According to Json.org, the valid json values are
"true"
and"false"
https://www.json.org/json-en.html
Recommend to update this to return the correct
"true"
/"false"
values.Reproduction Steps
Expected behavior
The test should pass because the value should be "true"
Actual behavior
The test returns "True"
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: