nqd / flat Goto Github PK
View Code? Open in Web Editor NEWFlatten/unflatten nested map or JSON object in Golang
License: MIT License
Flatten/unflatten nested map or JSON object in Golang
License: MIT License
Hello,
I am looking for a pkg that allows flattening a nested struct to map[string]string
so I can save it to a string based text file or KV store.
I find this pkg is almost there, except that when the value is an array or slice, extra handling is needed for my case.
Please consider adding such support. Thanks!
When merging maps with nil values current version of mergo
skips them
nested := make(map[string]interface{})
e := mergo.Merge(&nested, map[string]interface{}{"x": nil})
if e == nil {
fmt.Println(nested)
}
map[]
New version of mergo
allows us to change that behavior and avoid losing key-value pairs
nested := make(map[string]interface{})
e := mergo.Merge(&nested, map[string]interface{}{"x": nil}, func(c *mergo.Config) {c.Overwrite = true})
if e == nil {
fmt.Println(nested)
}
map[x:<nil>]
When unflattening something like
map[string]interface{}{
"pew.0": "woop",
}
The result is
map[pew:map[0:woop]]
or as a type map[string]map[string]interface{}
What I would expect is to be the result is
map[pew:[woop]]
or as a type map[string][]interface{}
Are there any plans to remedy this? Would you be willing to merge such a feature if I (or someone else) implemented it?
PS: I'm working on recursively unflattening input - I will upstream that in a PR here later :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.