News for hackers. Stuff that matters.
Re:When XML Beats JSON: UI Layouts by m1el on Wednesday October 30, 2019 @09:32AM (#21397473)
["div", "The ", ["a", {"href": "https://www.json.org/"}, "JSON format"], " was invented by ", ["em", "Douglas Crockford"], "."]
Re:When XML Beats JSON: UI Layouts by sacado2 on Wednesday October 30, 2019 @09:51AM (#21397696)
Quite readable but it's a hell to parse. The first argument is the name of the element, but what is the second one? If it is a string or an array, it's the first child, but if it's an object, it's the attribute set?
Re:When XML Beats JSON: UI Layouts by 52-6F-62 on Wednesday October 30, 2019 @10:04AM (#21397834)
Maybe something more like:

    [
        "div",
        [
            "The ",
            [
                "a",
                { "href": "https://www.json.org/" },
                [ "JSON format" ]
            ],
            " was invented by ",
            [
                "em",
                "Douglas Crockford"
            ],
            "."
        ]
    ]
With all children being encapsulated in an array...

edit: though it again gets confusing when the 0 index is sometimes the element type and sometimes the straight text... so never mind I guess the problem persists.

Re:When XML Beats JSON: UI Layouts by fnordsensei on Wednesday October 30, 2019 @04:57PM (#21402625)
That's is roughly how it's done in Reagent[1]/re-frame[2]:

  [:div "The" [:a {:href "https://www.json.org/"} "JSON format"]
   " was invented by " [:em "Douglas Crockford"] "."]
The fact that EDN[3] supports keywords makes it a bit easier to parse. Representing HTML in EDN this way was first done in a library called Hiccup[4], so it’s usually called “Hiccup” even when encountered outside of the original library.

1: https://holmsand.github.io/reagent/

2: https://github.com/Day8/re-frame

3: https://github.com/edn-format/edn

4: https://github.com/weavejester/hiccup

Re:When XML Beats JSON: UI Layouts by nkrisc on Wednesday October 30, 2019 @12:18PM (#21399353)
How would you ever differentiate "div" from an element or text? Is "The " text or the <The > tag?
Re:When XML Beats JSON: UI Layouts by arethuza on Wednesday October 30, 2019 @12:58PM (#21399862)
Why not just:

[ "div", "The ", [ "a", { "href": "https://www.json.org/" }, "JSON format" ], " was invented by ", [ "em", "Douglas Crockford" ], "." ]

First thing in array is element, if there is an object at the second location then that's the attributes?

Re:When XML Beats JSON: UI Layouts by 52-6F-62 on Wednesday October 30, 2019 @02:56PM (#21401206)
Yeah that seems to make the most sense. I had to actually work it out before I saw it. I was looking for some further separation beyond indices but I just ended up over-thinking it.
Re:When XML Beats JSON: UI Layouts by m1el on Wednesday October 30, 2019 @10:31AM (#21398146)
> The first argument is the name of the element, but what is the second one?

If the second argument is an object/dictionary, it's attributes. Otherwise, it's the first child. Alternatively, the ambiguity can be resolved by using null/0 instead of empty attributes.

Re:When XML Beats JSON: UI Layouts by kgwxd on Wednesday October 30, 2019 @09:58AM (#21397774)
What if text were quoted?
Re:When XML Beats JSON: UI Layouts by kickopotomus on Wednesday October 30, 2019 @11:41AM (#21398936)
Re:When XML Beats JSON: UI Layouts by postalrat on Wednesday October 30, 2019 @11:08AM (#21398550)
["div", "The", ["a[href=https://www.json.org/]", "JSON format"], "was invented by", ["em", "Douglas Crockford"], "."]
Re:When XML Beats JSON: UI Layouts by ilogik on Wednesday October 30, 2019 @09:46AM (#21397646)
that looks like the JSON documents in AWS's CloudFormation
Re:When XML Beats JSON: UI Layouts by iooi on Wednesday October 30, 2019 @12:27PM (#21399470)
Ok, now try <div>div</div>
Re:When XML Beats JSON: UI Layouts by arethuza on Wednesday October 30, 2019 @12:36PM (#21399590)
["div", "div"]
Re:When XML Beats JSON: UI Layouts by ses1984 on Wednesday October 30, 2019 @09:41AM (#21397576)
Interesting.