Why to submit data in json?

In all textbooks write that the data usually is passed in JSON format. I don't quite understand why you need to do it like that?
Let's say I can through a socket connection to transfer from node js server without the javascript object wrapper in json
Is it permissible to do so?
July 12th 19 at 16:53
4 answers
July 12th 19 at 16:55
Let's say I can through a socket connection to transfer from node js server without the javascript object wrapper in json
Can't websocket is a text - based Protocol, for transmission facilities required serialization, and json is perfect for this.
I use socket.io Apparently she serializes to json - fatima commented on July 12th 19 at 16:58
Apparently. But the books you have, most likely, not in the socket.io and web sockets in General, so there is said about the serialization in json. - parker commented on July 12th 19 at 17:01
July 12th 19 at 16:57
documentation
void send(
in DOMString data
);

void send(
in ArrayBuffer data
);

void send(
in Blob data
);
July 12th 19 at 16:59
JSON need to do not always, or in cases when you want with the API worked not only browser, but also mobile clients or the other (which does not need to prepare data in HTML, JSON and need to parse), or when it is better that the customer was fat. Even JSON, obviously, a few facilitates debugging.

Overall, ideally, the back-end of the website should be able to return HTML to the browser (which JS does not need to parse => performance on the client), and JSON for other purposes, and maybe something else.
This is done in VK, for example.

I'm talking about HTTP. If WebSockets encode all the fields in the JSON - do not worry, it is possible that such a feint ears:
{"html": "html here"}
And it is possible to do, elegantly combining the strengths of HTML and some of the advantages of JSON:
{"html": "html here", "error": "OK"}
I like Googleовских services seen. Interesting solution, and certainly has the right to life.
July 12th 19 at 17:01
json is a convenient format for data serialization. The ability to serialize/deserialize json in almost all programming languages, which makes this format quite universal.

If you are not going to use it - you will have to implement something else. It may be other serialization formats, such as messagepack, or if you want, pack these yourself as you want, depending on the task. But in this case you will have to implement serialization yourself, but this time. And time is money. Because it should be covered (for example, to increase the capacity to use your the binary format of serialisation designed exclusively for the task, although this is very rarely necessary and I doubt you'll need it next 5-10 years).

Find more questions by tags Node.js