3 ms·
This looks fantastic. I was recently reading a config file from Rust and ended up going with JSON5 but this is simpler to read. In a language like Rust you don'
by kevincox 6y ago
This looks fantastic. I was recently reading a config file from Rust and ended up going with JSON5 but this is simpler to read. In a language like Rust you don't need the types because you specify that in the struct anyways. Sure, this means that there are effectively more types than strings but the user doesn't need to differentiate.
In Rust you do something like this:
#[derive(Clone,serde::Deserialize)]
struct {
an_int: u64,
a_float: float,
ordered_map: linked_hash_map::LinkedHashMap<String, chrono::DateTime<chrono::Utc>>,
unordered_map: std::collections::HashMap<i32, String>,
}
So there is no need to worry about if maps are ordered or if a value is an integer, real or string in the format itself. Ironically for Python (which the reference implementation is in) it does seem much more annoying to have to manually call `int()` on each element.
I'm just a little sad that tabs are disallowed. I really think the best rule for indentation-sensitive languages is that each line must either have the same indentation in which case it is the same level, same indentation plus any amount in which case it is the next level, or the exact indentation of any previous level in which case it is a dedent. These "solutions" which just forbid tabs are half-assed and ones that try to convert tabs to a set amount of spaces just lead to confusion.
Additionally it would be nice if there was an example of a dict inside a list. I think it would work like the following but can't confirm from reading the site.
-
key: value
-
key: value
other-key: other-value
- kseistrup 6y agoCorrect. You'll get: [{'key': 'value'}, {'key': 'value', 'other-key': 'other-value'}]