fsprojects / FSharp.Data

F# Data: Library for Data Access
https://fsprojects.github.io/FSharp.Data
Other
814 stars 288 forks source link

A new FSharp.Data.JsonSaveOptions value needed #1482

Closed Thorium closed 1 year ago

Thorium commented 1 year ago

If you use production setting (as you should) of FSharp.Data.JsonSaveOptions.DisableFormatting 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 FSharp.Data.JsonSaveOptions.None, then there is way too much unnecessary characters for a production system. Could we consider adding a little bit more serialization options?

bonjune commented 1 year ago

https://github.com/fsprojects/FSharp.Data/blob/ef2eda4cb33386335e25d03e694668b0af6f0945/src/FSharp.Data.Json.Core/JsonValue.fs#L21-L27

I think we can add JsonSaveOptions.CompactUriAware case here?

Thorium commented 1 year ago

I would also be ok with having just a single space after every comma if that would be easier.

bonjune commented 1 year ago

Do you mean to change the behavior of the current DisableFormatting case? Although I can't imagine if there are any cases that rely upon the current behavior (no space after every comma), but I think it would be more safe to add a case for your case.