-
-
Notifications
You must be signed in to change notification settings - Fork 109
Open
Description
Hello,
-
I was trying to convert this python dictionnary
my_dict = { "apps": { "test": { "whatever_1": { "date": "2025-12-16", }, "whatever_2": { "date": "2025-12-16", }, }, }, }
...to this TOML output:
[apps] [apps.test] [apps.test.whatever_1] date = "2025-12-16" [apps.test.whatever_2] date = "2025-12-16"
-
I first had great hopes with:
print(tomlkit.dumps(my_dict))
but that outputs
[apps.test.whatever_1] date = "2025-12-16" [apps.test.whatever_2] date = "2025-12-16"
-
With a bit of pain, I eventually manage to get the expected output using:
my_dict_new = tomlkit.document() for category_name, apps in my_dict.items(): cat = tomlkit.table(False) for app_name, app_reports in apps.items(): app = tomlkit.table(False).indent(4) for report_name, report_data in app_reports.items(): rep = tomlkit.table(False).indent(4) for key, val in report_data.items(): rep.add(key, val).indent(4) app.append(report_name, rep) cat.append(app_name, app) my_dict_new.append(category_name, cat) print(tomlkit.dumps(my_dict_new))
As this the reverse scenario from #47 and #107 in which the target output here seemed to be the default .dumps() output at the time, I wonder whether there would be a quicker way to access the old behavior again (i.e. dump headers for parent nested headers) ?
Metadata
Metadata
Assignees
Labels
No labels