Skip to content

Commit

Permalink
Add a return after the outer closing brace in JSON formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
rs committed Aug 7, 2018
1 parent 1d68160 commit 1f610b9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions formatter/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ func (j *JSON) Write(p []byte) (n int, err error) {
case ' ', '\t', '\r', '\n':
// Skip spaces outside of quoted areas.
continue
}
switch b {
case '{', '[':
j.isValue = false
j.level++
Expand All @@ -76,6 +74,10 @@ func (j *JSON) Write(p []byte) (n int, err error) {
j.level = 0
}
cp = append(append(append(append(cp, '\n'), bytes.Repeat(indent, j.level)...), cs.Default...), b)
if b == '}' && j.level == 0 {
// Add a return after the outer closing brace.
cp = append(cp, '\n')
}
case ':':
j.isValue = true
cp = append(append(cp, cs.Default...), b, ' ')
Expand Down

0 comments on commit 1f610b9

Please sign in to comment.