Repository navigation
Clean nested string-keyed maps before JSON encoding - #190
Merged
hanzei merged 2 commits intoOct 20, 2026
Merged
Conversation
hanzei
requested changes
Oct 19, 2026
hanzei
left a comment
Collaborator
There was a problem hiding this comment.
Thanks!
Suggestion: have JSON() clean a copy instead of the receiver
JSON() writes the cleaned values back into the map it was called on (m[k] = cleanUp(v)). This PR makes that more visible: a top-level map[string]any value becomes an objx.Map once JSON(), MustJSON() or Base64() runs.
m := objx.Map{"config": map[string]any{"a": 1}}
_, _ = m.JSON()
_, ok := m["config"].(map[string]any)
// before this PR: ok == true
// after this PR: ok == false (m["config"] is objx.Map)
Contributor
Author
|
@hanzei I've changed
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Map.JSON()cleans nested interface-keyed maps, but skips them when they sit inside an ordinarymap[string]any. A YAML-style boolean key then causes JSON encoding to fail instead of being converted to a string.Recurse through string-keyed maps too. The regression covers a direct map and one inside a mixed array, and failed before the fix.
Full tests and
go vet ./...pass on Windows/Go 1.27. Changed-code golangci-lint passes; the full lint run reports existing gofmt differences inaccessors.go,doc.goandmap.go. Race testing is blocked locally because cgo is disabled.