Skip to content

Commit 8fcce8c

Browse files
authored
feat: more compact rendering of empty arrays and objects (#27)
1 parent 0ca7c16 commit 8fcce8c

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# ecslog changelog
22

3+
## Unreleased
4+
5+
- Make rendering of empty arrays and objects in the extra fields more compact.
6+
They are now rendered as "[]" and "{}" rather than "[\n]" and "{\n}".
7+
([#27](https://github.com/trentm/go-ecslog/pull/27))
8+
39
## v0.5.0
410

511
- Add a `-i, --include-fields FIELDS` flag for including only certain fields.

internal/ecslog/formatters.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ func formatJSONValue(b *strings.Builder, v *fastjson.Value, currIndent, indent s
335335
formatJSONValue(b, subv, currIndent+indent, indent, painter, compact, nestedIncludeFields)
336336
i++
337337
})
338-
if !compact {
338+
if !compact && i != 0 {
339339
b.WriteByte('\n')
340340
b.WriteString(currIndent)
341341
}
@@ -356,7 +356,7 @@ func formatJSONValue(b *strings.Builder, v *fastjson.Value, currIndent, indent s
356356
}
357357
formatJSONValue(b, subv, currIndent+indent, indent, painter, compact, includeFields)
358358
}
359-
if !compact {
359+
if !compact && len(v.GetArray()) != 0 {
360360
b.WriteByte('\n')
361361
b.WriteString(currIndent)
362362
}

0 commit comments

Comments
 (0)