INNER CODE UNIT · Go
neatEmpty
itaysk/kubectl-neat · cmd/neat.go:154
func neatEmpty(in string) (string, error) {
var err error
jsonResult := gjson.Parse(in)
var empties []string
findEmptyPathsRecursive(jsonResult, "", &empties)
for _, emptyPath := range empties {
// if we just delete emptyPath, it may create empty parents
// so we walk the path and re-check for emptiness at every level
emptyPathParts := strings.Split(emptyPath, ".")
for i := len(emptyPathParts); i > 0; i-- {
curPath := strings.Join(emptyPathParts[:i], ".")
cur := gjson.Get(in, curPath)
if isResultEmpty(cur) {
in, err = sjson.Delete(in, curPath)
if err != nil {
continue
}
}