diff --git a/main.go b/main.go index c6b4172..6b086d0 100644 --- a/main.go +++ b/main.go @@ -95,7 +95,7 @@ func quickCheckJSON(data []byte) error { } func cleanTrailingCommas(data []byte) ([]byte, error) { - re, err := regexp.Compile(`(?ms),(\s*[}\]])`) + re, err := regexp.Compile(`,(\s*([}\]]|$))`) if err != nil { return nil, err } diff --git a/main_test.go b/main_test.go index b516b62..507c4bd 100644 --- a/main_test.go +++ b/main_test.go @@ -34,6 +34,11 @@ func TestCleanTrailingCommas(t *testing.T) { "foo": 1 }`, }, + { + name: "final trailing comma", + input: `{"foo": "bar"},`, + output: `{"foo": "bar"}`, + }, } for _, c := range cases {