config: Preserve intentionally empty maps

Closes #14944
This commit is contained in:
Joe Mooring
2026-05-25 17:44:50 -07:00
committed by Bjørn Erik Pedersen
parent df5421918a
commit 80e60847fb
2 changed files with 10 additions and 5 deletions
+9 -5
View File
@@ -107,29 +107,33 @@ func (c ReplacingJSONMarshaller) MarshalJSON() ([]byte, error) {
if err != nil {
return nil, err
}
var removeZeroVAlues func(m map[string]any)
removeZeroVAlues = func(m map[string]any) {
var removeZeroValues func(m map[string]any)
removeZeroValues = func(m map[string]any) {
for k, v := range m {
if !hreflect.IsMap(v) && !hreflect.IsTruthful(v) {
delete(m, k)
} else {
switch vv := v.(type) {
case map[string]any:
removeZeroVAlues(vv)
if len(vv) == 0 {
// Keep intentionally empty map.
continue
}
removeZeroValues(vv)
if len(vv) == 0 {
delete(m, k)
}
case []any:
for _, vvv := range vv {
if m, ok := vvv.(map[string]any); ok {
removeZeroVAlues(m)
removeZeroValues(m)
}
}
}
}
}
}
removeZeroVAlues(m)
removeZeroValues(m)
converted, err = json.Marshal(m)
}
+1
View File
@@ -6,6 +6,7 @@ stdout 'Display project configuration'
hugo config
stdout 'baseurl = .https://example.com/'
stdout '\[contenttypes\.'
hugo config --format json
stdout '\"baseurl\": \"https://example.com/\",'