Hi everyone!
TOML has arrays:
array = [ [1, 0], [0, 1] ]
"array":[ [ 1, 0], [0, 1] ]
TOML has tables:
[table]
value = 1
"table":{ "value":1 }
TOML even has arraytables:
[[arraytable]]
value = 1
[[arraytable]]
value = 2
"arraytable":[ { "value":1 }, { "value":2} ]
But is there any way to do something like
"nested_array_table":[
[ { "value":1 }, {"value":0} ],
[ {"value":0}, {"value":1, "comment":"bottom right diagonal element"} ] ]
in TOML? If so, how can I do this? If not, why can't I do this?
I understand that there is always a way around this, by for instance flattening arrays
[[matrix]]
value = 1
[[matrix]]
value = 0
[[matrix]]
value = 1
[[matrix]]
value = 0
comment = "bottom right diagonal element"
or introducing _filler_ structs:
[[matrix.row]]
[[matrix.row.column]]
value = 1
[[matrix.row.column]]
value = 0
[[matrix.row]]
[[matrix.row.column]]
value = 1
[[matrix.row.column]]
value = 0
comment = "bottom right diagonal element"
However, none of these seems really appropriate. Also, in that case, TOML would be strict less expressive than JSON, which is kind of a pitty, since JSON is so darn unreadable.
One possible idea for an extension, which, I admit, scales not very well, would be to add additional layers of brackets around the table names: one for each level of array depth:
[[[matrix]]]
value = 1
[[matrix]]
value = 0
[[[matrix]]]
value = 0
[[matrix]]
value = 1
comment = "bottom right diagonal element"
This would be equivalent to the following JSON:
"matrix":[ [ { "value":1 }, { "value":0 } ], [ { "value":0 }, { "value":1, "comment":"bottom right diagonal element" } ] ]
Why does the lack of a matrix notation make TOML strictly less expressive than JSON? I'm interested to know, since I'm not aware of any such notation in JSON.
@fischmax: TOML has inline tables, so you should be able to write your example as follows (I think):
nested_array_table = [
[ {value = 1}, {value = 0} ],
[ {value = 0}, {value = 1, comment = "bottom right diagonal element"} ] ]
In #309 @jodastephen suggested an alternative grammar for array table:
[analyzers.filter]
[#]
type = "icu-tokenizer"
[#]
type = "lowercase"
[#]
type = "length"
min = 2
max = 35
If this is accepted, it can be easily extended to allow n-dimension matrix:
[nested_array_table]
[#]
[##]
value = 1
[##]
value = 0
[#]
[##]
value = 0
[##]
value = 1
comment = "bottom right diagonal element"
Any workaround?
IMO, this issue is a duplicate of #309. It can be closed in favour of that.
Closing as a duplicate of #309.
Most helpful comment
IMO, this issue is a duplicate of #309. It can be closed in favour of that.