Skip to content
This repository was archived by the owner on Apr 28, 2020. It is now read-only.

Commit 83f2b06

Browse files
Merge pull request #10 from mcraiha/array-ending-comma
Only add commas between array elements when needed
2 parents edfc83f + b47bc9b commit 83f2b06

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Json5/Json5Array.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,24 @@ internal override string ToJson5String(string space, string indent)
115115
{
116116
string newLine = string.IsNullOrEmpty(space) ? "" : "\n";
117117

118+
// TODO: Use string builder instead of string
118119
string s = "[" + newLine;
119120

121+
bool isFirstValue = true;
122+
120123
foreach (Json5Value value in this)
121-
s += (value ?? Null).ToJson5String(space, indent + space) + "," + newLine;
124+
{
125+
if (isFirstValue)
126+
{
127+
isFirstValue = false;
128+
}
129+
else
130+
{
131+
s += "," + newLine;
132+
}
133+
134+
s += (value ?? Null).ToJson5String(space, indent + space);
135+
}
122136

123137
s += indent + "]";
124138

0 commit comments

Comments
 (0)