News for hackers. Stuff that matters.
Re:When XML Beats JSON: UI Layouts by ChrisMarshallNY on Wednesday October 30, 2019 @07:58AM (#21396691)
The main reason that I use XML (occasionally) is because of XML Schema. It's a very precise data description that can be semantically verified.

Otherwise, I try to use JSON, where possible, because I am not a masochist.

Re:When XML Beats JSON: UI Layouts by arethuza on Wednesday October 30, 2019 @08:17AM (#21396836)
JSON Schema is pretty useful and is well supported by tools like VS Code
Re:When XML Beats JSON: UI Layouts by laggan on Wednesday October 30, 2019 @08:17AM (#21396839)
I actually found JSON Schema to be FAR FAR FAR easier to use than XML Schema.

https://json-schema.org/

Re:When XML Beats JSON: UI Layouts by ChrisMarshallNY on Thursday October 31, 2019 @10:00AM (#21408825)
You are correct.

I LOATHE XML Schema. I have used it for years, and have never memorized it. I still need to look it up like a n00b, every time I use it.

But the simple fact of the matter is, is that so many people and projects have inculcated it into hundreds (if not thousands) of toolsets and specs (Like -Ick- WSDL), that it really is the only viable game.

People tend to like JSON precisely because it eschews the kind of overhead that is the definition of XML Schema.

Re:When XML Beats JSON: UI Layouts by ChrisMarshallNY on Thursday October 31, 2019 @10:25AM (#21409138)
Huh. I just realized that JSON Schema is STILL not a published spec. It is currently in draft, and has been, for a long time.
Re:When XML Beats JSON: UI Layouts by halfdan on Wednesday October 30, 2019 @08:46AM (#21397066)
Does https://json-schema.org/ not work for you?
Re:When XML Beats JSON: UI Layouts by ChrisMarshallNY on Wednesday October 30, 2019 @09:55AM (#21397738)
It would, if anyone used it.

The thing about XML Schema, is that it is completely "baked into" pretty much every tool and library out there, so you can do "on-the-fly" runtime validation.

JSON is really about minimizing text. It works really well for this.

Another issue, is that JSON doesn't have comments, so it can be difficult to annotate a JSON file.

Re:When XML Beats JSON: UI Layouts by sacado2 on Wednesday October 30, 2019 @09:02AM (#21397211)
I don't know JSON schema really well; Can you say you want a `price` value to be a non-negative decimal value with at most two digits after the comma, and you want the `currency` value be exactly one of the following : "EUR", "USD", "GBP", the default if not specified being "EUR"?
Re:When XML Beats JSON: UI Layouts by itafroma on Thursday October 31, 2019 @06:18AM (#21407201)
Yes:

    {
        "$schema": "http://json-schema.org/draft-07/schema#",
        "type": "object",
        "properties": {
            "price": {
                "type": "number",
                "multipleOf": 0.01,
                "minimum": 0
            },
            "currency": {
                "type": "string",
                "enum": ["EUR", "USD", "GBP"],
                "default": "EUR"
            }
        }
    }