diff --git a/Json5/Json5Object.cs b/Json5/Json5Object.cs index 6f030cd..dc74c75 100644 --- a/Json5/Json5Object.cs +++ b/Json5/Json5Object.cs @@ -69,12 +69,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 (var property in this) { - s += indent + space + KeyToString(property.Key) + ": "; - s += (property.Value ?? Null).ToJson5String(space, indent + space) + "," + newLine; + if (isFirstValue) + { + isFirstValue = false; + } + else + { + s += "," + newLine; + } + + s += indent + space + KeyToString(property.Key) + ":"; + s += (property.Value ?? Null).ToJson5String(space, indent + space); } s += indent + "}";