toml icon indicating copy to clipboard operation
toml copied to clipboard

Array of tables output

Open 89z opened this issue 5 years ago • 4 comments

If I have this code:

import toml

in_s = '''
[[Winter]]
December = [
   { Sunday = 6 },
   { Monday = 7 }
]
January = [
   { Sunday = 6 },
   { Monday = 7 }
]
[[Spring]]
March = [
   { Sunday = 6 },
   { Monday = 7 }
]
April = [
   { Sunday = 6 },
   { Monday = 7 }
]
'''

m = toml.loads(in_s)
out_s = toml.dumps(m)
print(out_s)

I get this result:

[[Winter]]

[[Winter.December]]
Sunday = 6

[[Winter.December]]
Monday = 7

[[Winter.January]]
Sunday = 6

[[Winter.January]]
Monday = 7

[[Spring]]

[[Spring.March]]
Sunday = 6

[[Spring.March]]
Monday = 7

[[Spring.April]]
Sunday = 6

[[Spring.April]]
Monday = 7

Is it possible to get something closer to the input?

89z avatar Dec 09 '20 16:12 89z

As a first time contributor, this seems like a fun starting point. I'll give it a shot sometime in the next week.

snapperVibes avatar Dec 09 '20 18:12 snapperVibes

not sure how helpful it is, but I did find an implementation in C++ that produces the output I am talking about:

https://github.com/marzer/tomlplusplus

89z avatar Dec 09 '20 19:12 89z

Oddly enough, there is an unused method to dump inline tables. Considering Uiri did 90% of what was needed to implement inline tables in 2017 but never finished it, not having inline tables is likely a design choice (albeit one that I do not understand).

https://github.com/uiri/toml/blob/3f637dba5f68db63d4b30967fedda51c82459471/toml/encoder.py#L157

BTW, you can use this wrapper to get TomlPlusPlus's behavior in Python https://github.com/bobfang1992/pytomlpp, although it also does not output your TOML inline.

snapperVibes avatar Dec 09 '20 22:12 snapperVibes

I was just looking for this. :'(

henryiii avatar Jan 05 '21 01:01 henryiii