4 ms·
My opinion only: I love JSON because it lacks so many foot guns of yaml. If you’re doing lots of clever stuff with yaml you probably want a scripting language i
by Waterluvian 5y ago
My opinion only: I love JSON because it lacks so many foot guns of yaml. If you’re doing lots of clever stuff with yaml you probably want a scripting language instead. Django using Python for configs made me fall in love with this. Spending years with the unmitigated disaster that is ROS xml launchfiles and rosparams makes me love it even more.
Yaml and toml are fine if you keep it simple. JSON direly needs comments support (but of course wasn’t designed to be used as a human config file format so that’s kind of on us). And not just “Jsonc that sometimes might work in places.”
Beyond that, I think we generally have all the things we need and I don’t personally think we need yet another yaml. =)
- BugsJustFindMe 5y ago> Django using Python for configs made me fall in love with this. I also started advocating in-language configuration files (Python for Python, but also Lua for Lua, etc) a number of years ago because it lets you do really useful things (like functionally generating values, importing shared subsets of data, storing executable references, and ensuring that two keys return the same values without manual copy/paste) all without needing to spec and use Yet Another Thing™ that does only a fraction of what the programming language you're already using already does.
- eptcyka 5y agoThat also implies that you can't just test a foreign config file without first reading and understanding what it does, as just using one would imply arbitrary code execution.
- kevin_thibedeau 5y agoThis is a place where Tcl excels. You can easily create restricted sub-interpreters that can't do anything dangerous. If you need more power for trusted scripts you just reenable selected commands.
- spacechild1 5y agoSame thing with with Lua!
- pjmlp 5y agoThat is how our Tcl based application server was, the configuration files were a Tcl DSL.
- Jnr 5y agoUsing the programming language to do the comments works only when using some scripting language. Things that get compiled can't really use it without recompilation.
- mike_hock 5y agoBut you can embed Lua or Python using its C interface.
- woodruffw 5y agoThese aren't foot-guns per se, but I can think of another handful of grievances I have with JSON: * JSON streaming is a bit of a mess. You can either do JSONL, or keep the entire document in memory at once. I usually end up going with JSONL. * JSON itself doesn't permit trailing commas. I can measure the amount of time that I've wasted re-opening JSON files after accidentally adding a comma in days, not hours. * JSON has weakly specified numbers. The specification itself defines the number type symbolically, as (essentially) `[0-9]+`. It's consequently possible (and common) for different parsers to behave differently on large numbers. YAML also, unfortunately, has this problem. * Similarly: JSON doesn't clearly specify how parsers should behave in the presence of duplicate keys. More opportunity for confusion and bugs.
- secondcoming 5y ago2, 3 and 4 can be caught early with JSON schema.
- mirekrusin 5y agoNot really, json schema validation is applied after json parsing on already parsed json.
- afiori 5y agothe funny thing is that json doesn't even need commas, they essentially act as whitespace, any amount or no amount would make no difference in the meaning of the document. Arrays with hole are a JS-only feature
- the_jeremy 5y ago> json doesn't even need commas JSON is defined by the spec. The people who wrote the spec think otherwise[0]. [0]: https://www.json.org/json-en.html https://www.json.org/json-en.html > Arrays with hole are a JS-only feature. There are other langauges that allow arrays with missing elements.
- 5y ago
- timmytokyo 5y agoJSON5 is the way to go. It supports comments and trailing commas. Unfortunately it's going to be difficult to supplant legacy JSON, which is so pervasive.
- dheera 5y agoExcept parsing JSON5 in browser is super slow. Native JSON.Parse doesn't support it, non-native parsnips are slow, and the only fast way to parse it is `eval()`.
- TheCondor 5y agoDoes the browser need JSON objects with comments? The desire to use a single interchange format for all data is the problem. There are plenty of reasons to support comments and minor syntax issues that JSON itself dislikes for human consumable and interactive JSON. I'd think software JSON could be just that.
- The_Colonel 5y agoThis shouldn't really matter for the JSON5 use case - config files - which are usually small enough. For machine-to-machine generated payloads JSON is good enough.
- gmadsen 5y agoI work with ros extensively and have not heard of using django for this use case. do you know of any open source projects that do this?
- Waterluvian 5y agoSorry. Two separate contexts. I use both in the big picture but the Django world doesn’t directly interact with ROS. there’s an HTTP api for that.
- dmitriid 5y ago> My opinion only: I love JSON because it lacks so many foot guns of yaml. While true, parsing it is still a minefield because it's very underspecified: http://seriot.ch/projects/parsing_json.html http://seriot.ch/projects/parsing_json.html