News for hackers. Stuff that matters.
Re:XMPP For the Web with JSON by jacobolus on Monday May 13, 2013 @06:57PM (#5701989)
I don’t understand the point of taking an existing protocol – with fairly well defined syntax/semantics, which has presumably been tested at various parts of the stack, likely has existing conformance tests, &c. – and wrapping it in a new ad-hoc protocol which has (some subset of roughly) the same semantics, just for a syntax change? Big addition of new complexity for little tangible benefit.

Why not just use one of the existing Javascript implementations of an XMPP client, or if they’re unsuitable for whatever reason, make a new one?

Re:XMPP For the Web with JSON by jkarneges on Monday May 13, 2013 @07:25PM (#5702082)
Lately there's been discussion within the XMPP community about how web developers tend to prefer semi-proprietary connectivity solutions like Socket.io even though the XMPP standard and surrounding solutions predate these kinds of things. We believe a large part of the problem is the encoding format.

For better or worse, the web (and I mean all of it, not just browser<->webserver side) is transitioning to JSON for just about everything. Yes, it often seems like pointless wheel reinvention, but that's what is happening. May as well embrace the trend in order for our work to live on.

One funny thing about all this is that when XMPP was first created (as "Jabber" in 1999), XML was selected as the format because it was the current trend. In that sense XMPP was super hip in the beginning. Hard to believe now people look at XML and think it's a relic. With that in mind, I wonder what will happen to all these trendy JSON protocols being made today? Dinosaurs of tomorrow, probably. My feeling is that it's the underlying concepts that will live on, regardless of format.

Re:XMPP For the Web with JSON by spin on Monday May 13, 2013 @09:48PM (#5702616)
I don't want to start some kind of "XML vs JSON" holy war, but I really do prefer JSON over XML because of how compact and readable it is.

I really don't see JSON as a passing trend, I see it as (almost) the most compact, succint way to express hashmaps in both human-readable and machine-readable form. (XML is big, bloated, and bureaucratic.)

(It's tragic that Crockford left in all the qoutes around the keys, though. We really don't need to type those quotes.)

For the past couple of years, I really have been wishing for an "XMPP, but built on JSON, not XML". Really. I want this.

Re:XMPP For the Web with JSON by deno on Monday May 13, 2013 @11:24PM (#5702868)
> For the past couple of years, I really have been wishing for an "XMPP, but built on JSON, not XML". Really. I want this.

The X in XMPP stands for extensible not XML. The reason XML fits the bill is because it has concept of namespaces, what JSON has? If you don’t have explicit namespace support how do you make your JSON variant of XMPP forward‐compatible? You don’t without making it look much, much, worse than any of the examples I’m about to show below.

> (…) I really do prefer JSON over XML because of how compact and readable it is.

> XML is big, bloated, and bureaucratic.

My standard response to this is always “show me a JSON fragment that is shorter or prettier looking than an equivalent XML fragment.”

XML can certainly be shorter than JSON and often is, and repeated tags are the best showcase for it:

    <user id="abc">
       <phoneNo type="home">123456789</phoneNo>
       <phoneNo type="work">321654987</phoneNo>
    </user>
This turns into this beautiful JSON:

    [
      "users": [
	{
	  "id": "abc",
	  "phoneNos": [
	    { "type": "home", "value": "123456789" }, 
	    { "type": "work", "value": "321654987" }
	  ]
	}
      ]
    ]
Oh, but what if order is important? Take this example:

    <policy id="123">
        <drop someFilter="ghi" />
        <accept someFilter="abc" anotherFilter="xyz">
            <comment>
               This comment is quite long and spans several
               lines of text in pretty printed XML. 
               But this is quite alright, because XML
               by default strips extra whitespace.
            </comment>
            <!-- That’s another kind of comment, but this one is not meant
                 to be part of the data, unlike the one above. 
                 Some would say something as basic as comments is
                 an essential part of so called human‐readable format… --> 
        </accept>
        <drop someFilter="foo" anotherFilter="bar">
            <reason statusCode="690">No reason</reason>
        </drop>
    </policy>
Now you have to do it like that:

    [
      "policies": [
	{
	  "id": "123",
	  "rules": [
	    { "type": "drop", "someFilter": "ghi" },
	    { 
	      "type": "accept",
	      "someFilter": "abc",
	      "anotherFilter": "xyz",
	      "comment": "Unfortunately the best you can do with JSON is to rely on your editor’s dynamic wrapping. And this is how you break the line: \nWhat a treat!",
	    }, 
	    { "type": "drop", "someFilter": "foo", "anotherFilter": "bar", 
	      "reason": { "statusCode": 690, "message": "No reason"}
	    }
	  ]
	}
      ]
    ]
For an example of how horrible JSON in wild can really be see Reddit’s JSON API. Because JSON has no syntax for metadata you get things like that:

    [ 
      {
        "kind": "thing-foo",
        "items": [
           # 
           # list of comments or something that goes on for
           # two screens
           #
        ],
        "votes": 15
      }
    ]
See the keys are sorted for convenience.

XML’s text representation is very minimal and consistent. You don’t need to quote Every Single Thing, and there are no special cases for not quoting just some type of values. The only redundant part of XML is repeating the name of the closing tag if the </element> has value. But this actually aids readability, as demonstrated above.

Editing complex JSON by hand with a regular text editor is a nightmare, because of all those single '}', ']' and commas trailing for several lines when there’s any light nesting involved. Editing XML by hand on the other hand is no big deal.

Re:XMPP For the Web with JSON by harlanji on Tuesday May 14, 2013 @12:17AM (#5702992)
Thank you for this, I have bookmarked it for future reference!

I've always made the second part of your argument: that namespaces are the key feature that make XML useful, especially for the eXtensibility in XMPP. I also think that namespaces are a part of XML that few people understand, partially because many XML/XMPP implementations don't even (fully/correctly) support them.

The rest of what you say is new though! The solid examples you gave for compactness/ordering were impressively concise.

I'd even go further and say they generally illustrate the difficult readability that can arise in JSON with not-so-difficult requirements--I had more trouble following the JSON than the XML here, by far. I'd say the embedded comments and possibility of a schema in XML are also a bonus, to help understand the meaning if it isn't obvious.

I am by no means an XML-supremicist, but I do take the unpopular view that it is a much more future-proof and natural solution for many more use-cases than it gets credit for. I'd love to see a successor that cuts out some of the warts as much as the next person, but every solution has pros/cons, and XML is a pretty good balance in a lot of cases where people refuse to look at it.

Re:XMPP For the Web with JSON by spin on Wednesday May 15, 2013 @01:08AM (#5710270)
------- Quoting the parent:

This turns into this beautiful JSON:

    [
      "users": [
	{
	  "id": "abc",
	  "phoneNos": [
	    { "type": "home", "value": "123456789" }, 
	    { "type": "work", "value": "321654987" }
	  ]
	}
      ]
    ]
------ ... endquote.

That's a strange, contrived example. In Javascript, I would write it like this:

user = {id: "abc", homePhone: "123456789", workPhone: "321654987"};

(And the next time that object goes across the network, my libraries will be nice enough to put the quotes around the keys for me.)

Re:XMPP For the Web with JSON by deno on Wednesday May 15, 2013 @03:18AM (#5710640)
That’s not at all strange – the type is variable and can be specified by user. Not to mention you can have more than one home or work number. You sure can serialize your data to your keys, but then that would be rather strange.

Anyway just imagine there’s an extra field, problem solved:

    <phoneNo type="home" priority="1">…</phoneNo>
Re:XMPP For the Web with JSON by cs02rm0 on Tuesday May 14, 2013 @03:50AM (#5703484)
Not sure why you'd edit JSON by hand in general. It doesn't tend to be used for configuration files, AIUI this move is following the trend of sending JSON over the web. So surely looking at parsing JSON vs. XML in a browser is where the real comparison is?
Re:XMPP For the Web with JSON by deno on Tuesday May 14, 2013 @02:22PM (#5706886)
This is the most peculiar thing about the JSON mania of all. I mean your web browser programming consists of 99% DOM manipulation and suddenly everyone forgets how to do that when it comes to making Web API calls. Maybe we need jQuery for XML?
Re:XMPP For the Web with JSON by spin on Wednesday May 15, 2013 @01:12AM (#5710281)
My programming consists of 99% Javascript, ie, manipulating Javascript objects. The data structures (ie objects) translate flawlessly into JSON (I just gotta remember the quotes around the keys, is all...). Switching my brain from Javascript to the-data-across-the-network (and back) requires practically no effort at all, because it's the same thing.

EDIT:

> Maybe we need jQuery for XML?

Adding more layers of complexity to deal with complexity? I am further convinced that XML is bloated and bureaucratic. I am so happy that modern browsers let met get away from jQuery. Plain, vanilla JS is better for the soul.

Re:XMPP For the Web with JSON by jakerocheleau on Monday May 13, 2013 @07:27PM (#5702089)
I don't have an answer but I do have a follow-up question.

There are no pre-built GChat clients and I have been planning to create one using Phono, which is built on jQuery. Are there better solutions other than this, or the linked example Superfeedr?

Google Chat is my main IM client and I know it's built on XMPP. I just want to pick a solid JS library to build with and make a web interface that can work for people.

Re:XMPP For the Web with JSON by shmerl on Monday May 13, 2013 @07:31PM (#5702106)
You can also use something like Strophe.js to build your own client. Or you want to add an XMPP/Jingle support as well? How exactly would it work, through routing Jingle over WebRTC?

Update: I just looked at Phono - it doesn't seem like it supprots XMPP/Jingle, even though it uses WebRTC. So this kind of defeats the purpose, since you can't initiate audio/video calls to other XMPP clients.

Can you advise any combinations of JavaScript client libraries and XMPP servers (i.e. without a need to use third party gateways) which can already normally support XMPP over WebSockets and Jingle over WebRTC?

Re:XMPP For the Web with JSON by mweibel on Tuesday May 14, 2013 @12:51AM (#5703066)
XMPP over Websockets is implemented in various servers:

  - Prosody (http://code.google.com/p/prosody-modules/wiki/mod_websocket)
  - openfire (http://code.google.com/p/openfire-websockets/)
  - Tigase (built-in as far as I could see)
  - Ejabberd in the Commercial version, the opensource version doesn't really have one yet.
Regarding Jingle over WebRTC: Various people are working on it (or have been, in my case) and it's getting closer to workable. What I encountered, when I tried ~a year ago to do it, was that not all SDP messages could be easily transformed into the Jingle format. Might have been changed now though as the WebRTC Specs have changed quite a bit.
Re:XMPP For the Web with JSON by shmerl on Tuesday May 14, 2013 @01:24PM (#5706419)
Thanks for the pointers. I hope open source ejabberd will catch up, since I prefer it in general. Are any of the Jingle through WebRTC projects public to track their progress?
Re:XMPP For the Web with JSON by shmerl on Monday May 13, 2013 @07:29PM (#5702096)
I agree. It's better to help improving current XMPP libraries for good support of WebSockets and etc. instead of bringing JSON into the picture.