-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
System.Text.Json, addition needed for JsonWriterOptions, to avoid URI serialization issue #95182
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsIf you use System.Text.Json with JsonWriterOptions, by default settings (Indented off), it will create a following JSON: ...which looks correct to me, but as you can see, the major automatic parsers like GitHub, Google, Microsoft, etc fail to end the url link to the end-quote, and treat the URL as combining all the rest of the stuff going as part of that url. And as you can see, the full url is not working. If a single space is added after the comma, then behold, the parsers are clever now: If you do Indented=true, then there is way too much unnecessary characters for a production system.
|
This, to me, seems like a bug in their parsers. STJ is producing valid JSON. |
if all the parsers are doing it wrong, we'd need to adopt... |
I disagree. Deviation from standard should never become common practice. |
Could you share an example of a JSON parser that is doing this? It seems pretty flagrant. Generally speaking the STJ parser is pretty strict about compliance of the JSON that it accepts, see #32291 (comment). |
GitHub is not “parsing” the JSON in your example. It’s just a markdown rendering that automatically converts links in to clickable links. Our markdown pipeline does not look in issue content for “does this look like JSON?” and try to interpret it. I would expect someone to use a code fence in this situation to avoid this. {"url":"https://google.com","prop":"x"} Spacing aside, you will still run in to problems with less than or greater than signs For example, this would incorrectly be displayed: {
"potato": "foo<bar>"
} { As <bar> is interpreted as an HTML tag. |
Adding one spacing option that is still within the standard syntax shouldn't be too hard... I don't even mind Github but the same is done by Word, Outlook and others. My problem is that I provide WebApi returning JSON and the customers of that API complain the URLs being wrong, and when things are escalated to manager level, the managers clearly see the URLs being wrong. I would expect the case not to be unique. Edit: Of course one can just say |
It's adding yet another source of branching in the hot path though. We might consider it if this were some kind of web standard, but it seems to me that the only motivating use case is to provide a workaround for a specific bug in tools that weren't designed to display JSON in the first place. And per @vcsjones's comment it's not even solving the problem in its entirety. Does Json.NET have a formatting option that works around the issue? |
If you do |
But isn't it the case that this only controls the indentation level and the indentation char (FWIW we're tracking an equivalent feature in #63882)? That wouldn't suffice to give you the desired behavior though. |
As there are workarounds available, and this seems to be not supported scenario in the near future, I'll just close this issue. |
If you use System.Text.Json with JsonWriterOptions, by default settings (Indented off), it will create a following JSON:
{"url":"https://google.com","prop":"x"}
...which looks correct to me, but as you can see, the major automatic parsers like GitHub, Google, Microsoft, etc fail to end the url link to the end-quote, and treat the URL as combining all the rest of the stuff going as part of that url. And as you can see, the full url is not working.
If a single space is added after the comma, then behold, the parsers are clever now:
{"url":"https://google.com", "prop":"x"}
If you do Indented=true, then there is way too much unnecessary characters for a production system.
Could we consider adding a serialization option of "a space after comma", please?
The text was updated successfully, but these errors were encountered: