✨ Add support for mixed-level nested keys with dot/blank handling
- Handle @parent:child and @parent🧒grandchild coexistence
- Use '.' key for parent values when nested children exist
- Add comprehensive test cases for double-nested scenarios
- Support both '.' and '' as special keys for parent values
This commit is contained in:
parent
44ecfd6ac9
commit
6095c2497e
3 changed files with 53 additions and 5 deletions
|
|
@ -42,6 +42,7 @@ func (ms Metas) Map() map[string]any {
|
|||
}
|
||||
|
||||
func parseNestedFields(f map[string]any) {
|
||||
todelete := make([]string, 0, len(f))
|
||||
for k, v := range f {
|
||||
if strings.Contains(k, ":") {
|
||||
idx := strings.Index(k, ":")
|
||||
|
|
@ -50,14 +51,28 @@ func parseNestedFields(f map[string]any) {
|
|||
|
||||
nest, ok := f[top].(map[string]any)
|
||||
if !ok {
|
||||
nest = map[string]any{}
|
||||
curr := f[top]
|
||||
if curr == nil {
|
||||
nest = map[string]any{}
|
||||
} else {
|
||||
nest = map[string]any{".": curr}
|
||||
}
|
||||
}
|
||||
|
||||
curr, ok := nest[bottom].(map[string]any)
|
||||
if ok {
|
||||
curr["."] = v
|
||||
} else {
|
||||
nest[bottom] = v
|
||||
}
|
||||
nest[bottom] = v
|
||||
parseNestedFields(nest)
|
||||
f[top] = nest
|
||||
delete(f, k)
|
||||
todelete = append(todelete, k)
|
||||
}
|
||||
}
|
||||
for _, k := range todelete {
|
||||
delete(f, k)
|
||||
}
|
||||
}
|
||||
|
||||
// Implements json.Marshaler
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue