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

Only add commas between array elements when needed #10

Merged
merged 1 commit into from
Aug 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion Json5/Json5Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,24 @@ internal override string ToJson5String(string space, string indent)
{
string newLine = string.IsNullOrEmpty(space) ? "" : "\n";

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

bool isFirstValue = true;

foreach (Json5Value value in this)
s += (value ?? Null).ToJson5String(space, indent + space) + "," + newLine;
{
if (isFirstValue)
{
isFirstValue = false;
}
else
{
s += "," + newLine;
}

s += (value ?? Null).ToJson5String(space, indent + space);
}

s += indent + "]";

Expand Down