@@ -26,6 +26,11 @@ type JsonSaveOptions =
2626 /// Print the JsonValue in one line in a compact way
2727 | DisableFormatting = 1
2828
29+ /// Print the JsonValue in one line in a compact way,
30+ /// but place a single space after every comma
31+ /// https://github.com/fsprojects/FSharp.Data/issues/1482
32+ | CompactSpaceAfterComma = 2
33+
2934/// Represents a JSON value. Large numbers that do not fit in the
3035/// Decimal type are represented using the Float case, while
3136/// smaller numbers are represented as decimals to avoid precision loss.
@@ -67,6 +72,13 @@ type JsonValue =
6772
6873 let propSep = if saveOptions = JsonSaveOptions.None then " \" : " else " \" :"
6974
75+ let comma () =
76+ match saveOptions with
77+ | JsonSaveOptions.None -> w.Write " ,"
78+ | JsonSaveOptions.DisableFormatting -> w.Write " ,"
79+ | JsonSaveOptions.CompactSpaceAfterComma -> w.Write " , "
80+ | _ -> failwith " Invalid JsonSaveOptions"
81+
7082 let rec serialize indentation =
7183 function
7284 | Null -> w.Write " null"
@@ -83,7 +95,7 @@ type JsonValue =
8395
8496 for i = 0 to properties.Length - 1 do
8597 let k , v = properties.[ i]
86- if i > 0 then w.Write " , "
98+ if i > 0 then comma ()
8799 newLine indentation 2
88100 w.Write " \" "
89101 JsonValue.JsonStringEncodeTo w k
@@ -96,7 +108,7 @@ type JsonValue =
96108 w.Write " ["
97109
98110 for i = 0 to elements.Length - 1 do
99- if i > 0 then w.Write " , "
111+ if i > 0 then comma ()
100112 newLine indentation 2
101113 serialize ( indentation + 2 ) elements.[ i]
102114
0 commit comments