3 ms·
How does TOML solve the “do I want an int or do I want a string." part? I only know YAML and this caught me a few times, would love to know how toml does it.
by Kamshak 9y ago
How does TOML solve the “do I want an int or do I want a string." part? I only know YAML and this caught me a few times, would love to know how toml does it.
- yeukhon 9y agoNone of them do, sorry if I was being too casual. The reason I named YAML because in YAML you can just write name: bob where bob is assumed to be a string by the YAML parser. This is bad if you use Ansible because "bob" could be the name of a variable. bob: "I am bob" name: bob # at runtime Ansible sees 'name: "I am bob"' But both JSON and TOML need the users to be more explicit. So while users still need to be mindful of "1" vs 1, JSON and TOML don't assume as much as YAML does. Let me show you in Python. import toml import yaml s1 = "name: bob" yaml.load(s1) --> {'name': 'bob'} s2 = "name = bob" toml.loads(s2) Traceback (most recent call last): .... File ".../python2.7/site-packages/toml.py", line 664, in _load_value v = int(v) ValueError: invalid literal for int() with base 10: 'bob' s3 = "name = bob eve" toml.loads(s3) Traceback (most recent call last): raise TomlDecodeError("This float doesn't have a leading digit") See how a space and without space yield a different exception different? Not sure if it's an implementation problem, or the spec says so though. But the point is TOML doesn't assume "bob" without a quote is a string, which is a good thing.