Reputation: 3106
YAML appears to be more readable than a JSON formatted object, apart from readability what advantages or disadvantages does PyAML have instead of JSON? How should we make a decision between the two, note that I am not asking the difference between the two but recommendations on why and when to use one over the other?
Upvotes: 9
Views: 11829
Reputation: 4160
There are one or two big differences between YAML and JSON that can (should) be stated quickly that are missing (or not prominent) in comprehensive answers like the one mentioned in the question comment.
While YAML does not permit TAB characters for indentation, it is still an indent defined format. If you think your files may get mishandled and squashed around from a white space perspective (e.g. copy pasted off the web) you may prefer JSON.
You can specify a JSON key which contains only numbers but the key will still be a string and will require a convention or a format specification if that's going to get transformed into an actual int
within your language. If you are going to need genuine numeric keys you may prefer YAML.
I think I'm right to say all valid JSON is valid YAML, even as far as accepting TAB characters in JSON sections which are not indent defined. If you can afford to use a YAML parser then you've got JSON as well if you want that restriction.
Even now I think it's fairly incontrovertible to say that you can find JSON support almost everywhere, so choosing JSON will maximise your compatibility.
So TOML is a great candidate:
If you can afford to lose the universal support this is a great alternative to YAML, offering some nifty compact hash table definition alternatives, with the robustness of a non-indent format like JSON, but, sadly, still no genuine numeric keys.
Sorry Minas, I'm not going to say anything nice about XML today.
Upvotes: 1
Reputation: 379
JSON is more formal format than YAML. IMHO:
Upvotes: 6