Skip to content

Add Encoder option to disable printing of super-table header #957

@katexochen

Description

@katexochen

The following example

type a struct{ B b }
type b struct{ C c }
type c struct{ D d }
type d struct{ S string }

func main() {
	var test a
	test.B.C.D.S = "foo"
	out, err := toml.Marshal(test)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(out))
}

will output the following marshaled toml:

[B]
[B.C]
[B.C.D]
S = 'foo'

Citing the TOML spec

# [x] you
# [x.y] don't
# [x.y.z] need these
[x.y.z.w] # for this to work

So it would be nice if there would be a way to omit the empty super-table headers.

This is especially useful in case your last element in the path (D/w) is known to be unique, and you want to append a toml snippet to an existing toml file. If you marshal the snippet and it contains the empty super-table headers, you might redefine the super-table if it is already present in the file your appending to.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureIssue asking for a new feature in go-toml.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions