Skip to content

Commit 27710e6

Browse files
committed
Allow trailing commas in arrays and objects
1 parent 6f415f1 commit 27710e6

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

  • StyleCop.Analyzers/StyleCop.Analyzers/LightJson/Serialization

StyleCop.Analyzers/StyleCop.Analyzers/LightJson/Serialization/JsonReader.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,15 @@ private JsonObject ReadObject(JsonObject jsonObject)
358358
this.scanner.SkipWhitespace();
359359

360360
var next = this.scanner.Read();
361+
if (next == ',')
362+
{
363+
// Allow trailing commas in objects
364+
this.scanner.SkipWhitespace();
365+
if (this.scanner.Peek() == '}')
366+
{
367+
next = this.scanner.Read();
368+
}
369+
}
361370

362371
if (next == '}')
363372
{
@@ -407,6 +416,15 @@ private JsonArray ReadArray(JsonArray jsonArray)
407416
this.scanner.SkipWhitespace();
408417

409418
var next = this.scanner.Read();
419+
if (next == ',')
420+
{
421+
// Allow trailing commas in arrays
422+
this.scanner.SkipWhitespace();
423+
if (this.scanner.Peek() == ']')
424+
{
425+
next = this.scanner.Read();
426+
}
427+
}
410428

411429
if (next == ']')
412430
{

0 commit comments

Comments
 (0)