News for hackers. Stuff that matters.
Re:Libvirt – The Unsung Hero of Cloud Computing (2013) by foepys on Friday September 04, 2020 @12:53AM (#24371803)
JSON is a bad configuration format simply for the fact that it doesn't support comments. Some parsers do but most don't. XML for all its verbosity and complexity at least has comments where I can quickly try out configuration changes without needing to save the old configuration somewhere else.

Hell, even INI files had support for comments and were just as expressional as JSON. I wonder why we regressed in that regard. Was it just because of the success of JavaScript and readily available JSON parsers? Because I'd argue that an INI parser is just as easy to write.

Re:Libvirt – The Unsung Hero of Cloud Computing (2013) by japanuspus on Friday September 04, 2020 @01:23AM (#24371948)
This is exactly why TOML [0] is gaining traction as a simple configuration file format. Rust's cargo has been TOML from day one (`Cargo.toml`) and Python is moving this way with (`pyproject.toml`).

For more general data structures, remember that JSON is a true subset of YAML [1]: Switch to a YAML parser and you can start optionally adding comments to your files while still being compatible with legacy input.

[0] https://toml.io/en/ [1] https://yaml.org/

Re:Libvirt – The Unsung Hero of Cloud Computing (2013) by eska on Friday September 04, 2020 @05:24AM (#24373253)
Yaml is generally derided as too complex and transforming data in unintended ways.

I see a lot of Rust programmers preferring RON over TOML because it is much less complex and doesn't have multiple ways to express the same thing https://crates.io/crates/ron

Re:Libvirt – The Unsung Hero of Cloud Computing (2013) by bbotond on Friday September 04, 2020 @06:34AM (#24373679)
I hate YAML. XML and JSON have syntaxes that are very easy to learn. You basically see one example and know 99% of what you need. YAML has multiple ways of doing the same thing (eg. two array syntaxes) and is generally too "clean" looking to the point of being unreadable.
Re:Libvirt – The Unsung Hero of Cloud Computing (2013) by jmillikin on Friday September 04, 2020 @05:04AM (#24373151)

  > For more general data structures, remember that JSON is
  > a true subset of YAML [1]
This is unfortunately not true -- try the input '{"a":1e2}'.
Re:Libvirt – The Unsung Hero of Cloud Computing (2013) by rurban on Friday September 04, 2020 @04:47AM (#24373038)
YAML has too many features, and is entirely insecure. You really need a safe subset, as eg. used in the various CI's.
Re:Libvirt – The Unsung Hero of Cloud Computing (2013) by staeke2 on Friday September 04, 2020 @01:42AM (#24372056)
Because JSON was designed explicitly not to be a config format but a serialization format. For configs, use JSON5. At leatst imo seems most sane config formats are json5 these days.
Re:Libvirt – The Unsung Hero of Cloud Computing (2013) by formerly_proven on Friday September 04, 2020 @03:44AM (#24372686)
> JSON is a bad configuration format simply for the fact that it doesn't support comments. Some parsers do but most don't. XML for all its verbosity and complexity at least has comments where I can quickly try out configuration changes without needing to save the old configuration somewhere else.

Do this with libvirt please and report back how it went :)

Re:Libvirt – The Unsung Hero of Cloud Computing (2013) by necovek on Friday September 04, 2020 @05:33AM (#24373319)
Libvirt uses proper XML parser so that's almost certainly a non-issue. The problem with libvirt XML files is that they are snapshots, and that they lack obvious defaults.

What I mean with "snapshots" is that you can't edit an XML file for a running VM on disk, but instead have to go through either virt-manager or virsh dump/load function. If you do edit an existing XML file on disk, it will just overwrite it for you.

And XML format is a bit more verbose simply because XML schema writers make it so. SGML could be even nicer for human writers.

As for comments in JSON, many parsers are not strict and would let you insert arbitrary elements, so you might add {"comment":"whatevah"} where you need it.

An example of terse XML would be:

<vm name="postgres">

  <ram size="8gb"/>

  <disk size="1tb"/>
</vm>

or

<vm>

  <name>postgred</name>

  <ram>8gb</ram>

  <disk>1tb</disk>
</vm>

compared to JSON:

{

  "name": "postgres",

  "ram": "8gb",

  "disk":"1tb" 
}

They are not equally descriptive, but that's because you do not need a top-level element in JSON (you could have it).

Re:Libvirt – The Unsung Hero of Cloud Computing (2013) by dijit on Friday September 04, 2020 @04:34AM (#24372974)
I actually _do_ do this quite often. Often w.r.t local changes (attaching network devices or storage devices).

If you fire up `virsh edit <resource>` you get a live view of the resource which can be updated in place. This is great to comment out some things and uncomment things for quick and dirty modifications. (some require a VM restart though).

Re:Libvirt – The Unsung Hero of Cloud Computing (2013) by formerly_proven on Friday September 04, 2020 @05:31AM (#24373311)
That has to be a recent change, because editing the XML used to cause it to roundtrip through libvirt, which doesn't keep the XML DOM around; anything not in the internal C structs would be removed from the files, including all comments.
Re:Libvirt – The Unsung Hero of Cloud Computing (2013) by dijit on Friday September 04, 2020 @11:05AM (#24375569)
I’m not sure fully how it works internally I’m afraid. But I was doing this in 2013-2014 if that’s any indicator of timeframe.
Re:Libvirt – The Unsung Hero of Cloud Computing (2013) by formerly_proven on Friday September 04, 2020 @11:59AM (#24376123)
Weird, I've done it quite recently on a Debian system and it reformatted & removed everything it doesn't know from the XML. If you Google this, it's a common issue and apparently the reason why the top-level "metadata" tag was added, because that metadata-tag is carried around as DOM, so doesn't get purged.
Re:Libvirt – The Unsung Hero of Cloud Computing (2013) by Erlich_Bachman on Friday September 04, 2020 @04:14AM (#24372835)
INI only supports 2 levels of hierarchy? That is not equivalent.
Re:Libvirt – The Unsung Hero of Cloud Computing (2013) by foepys on Friday September 04, 2020 @05:22AM (#24373244)
You can use dots in section names. Some JSON configuration parsers use dots to traverse the hierarchy, so even the API stays the same.
Re:Libvirt – The Unsung Hero of Cloud Computing (2013) by vbezhenar on Friday September 04, 2020 @01:06AM (#24371858)
Sometimes you can just add property "comment" or something like this.
Re:Libvirt – The Unsung Hero of Cloud Computing (2013) by z3t4 on Friday September 04, 2020 @01:27AM (#24371963)
I load config files as JS (not JSON). And only use JSON for data serialization. In plain JS you can have comments and dont have to put quotes around properties. Not saying everyone should have a full JS parser for their config files, but its really nice.
Re:Libvirt – The Unsung Hero of Cloud Computing (2013) by eska on Friday September 04, 2020 @05:26AM (#24373268)
So you're running eval on your config data? Not feasible for external data.
Re:Libvirt – The Unsung Hero of Cloud Computing (2013) by z3t4 on Friday September 04, 2020 @07:45AM (#24374063)
In module context. Then

    var config = require("settings.js");
My reasoning is that if you have access to change config or source code, all bets are off.

Or you could parse the config in a separate vm and import the result as JSON.