TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

No JSON/MAPS interoperability in 17.0?

44 pointsby rahijabout 11 years ago

20 comments

jerfabout 11 years ago
Erlangers are particularly grumpy about JSON because unlike many other languages, Erlang lacks a decent default serialization and deserialization of JSON. This is primarily due to the fact that a string is a list of integers, thus making it hard to distinguish between the two, and somewhat less importantly, but still problematic, the klunkiness of the dictionaries. (This message appears to be in the context of the soon-to-come native addition of dictionaries, but as I imply, unfortunately that is not the biggest problem with JSON deserialization, the nature of strings in Erlang is. Binaries are not a precise conceptual match to a JSON string either, unfortunately; in my environment I actually use binaries that way because I can guarantee the differences won&#x27;t affect me since I control both ends of the protocol, but that is not safe in general.)<p>This is not to say that the arguments are wrong, but I think you may not understand why Erlangers feel the way they do until you realize that Erlangers also don&#x27;t generally get to experience the <i>advantages</i> of JSON, either; when you get none of the advantages and only the disadvantages, anything looks bad, no matter how good it may be in the abstract.<p>This is a particularly rich irony in light of the fact that Erlang&#x27;s native data model is <i>conceptually</i> the closest language I know to natively using JSON as the only data type. Erlang has no user-defined types, and everything is an Erlang term... imagine if JS worked by only allowing JSON, so, no objects, no prototypes, etc. The entire language basically works by sending &quot;ErlON&quot; around as the messages, including between nodes. It&#x27;s just that there&#x27;s no good mapping whatsoever between Erlang&#x27;s &quot;ErlON&quot; and JSON.
评论 #7398743 未加载
评论 #7399871 未加载
NathanKPabout 11 years ago
The first requirement that I look for in a data interchange format is that it should be readable, because I don&#x27;t want to look at binary data responses. The second thing I look at is support for encoding and decoding it.<p>The only three formats I&#x27;ve found so far that are readable and well supported are XML, JSON, and YAML. XML is too hefty and wasteful. YAML has had a bad history of insecure encoders and decoders but overall is my favorite data format. However, it still has the downside of needing a special decoder since browsers don&#x27;t support it, and it requires specific indentation for its hierarchical data format which is wasteful in its own way.<p>That just leaves JSON in my opinion. It&#x27;s easily understood and read, and native browser and Node.js encoding and decoding is more than fast enough.
评论 #7398865 未加载
评论 #7398973 未加载
评论 #7398892 未加载
评论 #7398874 未加载
评论 #7398885 未加载
评论 #7398896 未加载
评论 #7399201 未加载
jfosterabout 11 years ago
This essentially amounts to &quot;JSON is slower and more CPU intensive than it absolutely needs to be.&quot;<p>I can live with that. Any solution that people come up with, there will be folks who can point out some sort of flaw in it. Sometimes the flaws are worth paying some attention to, when fixing them might lead to some tangible benefits. It&#x27;s difficult to imagine a slightly less CPU intensive replacement for JSON bringing any tangible benefits with it, though.
评论 #7398913 未加载
评论 #7398785 未加载
MagicWishMonkeyabout 11 years ago
Using something other than JSON is a great idea if you don&#x27;t want anyone to ever bother using your API.
评论 #7398833 未加载
评论 #7398759 未加载
haplessabout 11 years ago
Only an Erlang mailing list would prompt someone to complain that a document format requires valid UTF-8.<p>This is a glimpse of the last place on earth where relying on US ASCII is considered a positive good.
评论 #7398894 未加载
评论 #7401129 未加载
评论 #7398831 未加载
antirezabout 11 years ago
Prefixed length formats that don&#x27;t make assumptions on encoding are a very good pick. The most important thing is that once you read the length, you can just bulk-read the payload without actually parsing it, that&#x27;s up to the higher layer (if parsing is needed at all).<p>A general purpose serialization format that requires per-char processing is a terrible pick.
评论 #7398842 未加载
nubsabout 11 years ago
&gt; Its numbers representation is double-precision floating-point, meaning it&#x27;s incredibly imprecise and limited.<p>Except that JSON actually just specifies the number type as an arbitrary precision decimal number.<p>Many implementations use floating point numbers when decoding JSON, but that is not inherent in JSON.<p>My biggest complaint about numbers in json is that often times floating point numbers get turned into integers when encoding&#x2F;decoding using some implementations. (e.g. (float)2 gets encoded as just 2 and when decoding, it is an integer rather than a floating point.
评论 #7398870 未加载
jcizzleabout 11 years ago
JSON and Erlang just don&#x27;t get along in the way you&#x27;d like them to, unfortunately. Some of that has to do with how Erlang handles (or doesn&#x27;t handle) strings. Some of that was that there was not a data structure that closely mirrored JSON&#x27;s structure in Erlang up until Maps were introduced.<p>The problem isn&#x27;t really JSON - JSON is an exceptional format for what it is supposed to do - the problem is that Erlang was created for a specific purpose and that purpose wasn&#x27;t to vend out strings&#x2F;JSON over HTTP.
评论 #7398817 未加载
denzquixabout 11 years ago
Since the author seems to have a problem with text-based formats in general, here&#x27;s a counterpoint by Mike Pall on the LuaJIT mailing list [1]:<p>&quot;On a tangent: IMHO most binary serialization formats like BSON, MessagePack or Protocol Buffers are misdesigns. They add lots of complications to save a couple of bytes. But that does not translate into a substantial improvement of the parsing speed compared to a heavily tuned parser for a much simpler text-based format.&quot;<p>[1] <a href="http://www.freelists.org/post/luajit/Adding-assembler-code-to-Lua-programs,12" rel="nofollow">http:&#x2F;&#x2F;www.freelists.org&#x2F;post&#x2F;luajit&#x2F;Adding-assembler-code-t...</a>
arethuzaabout 11 years ago
So don&#x27;t use JSON when you need super high performance and be careful about parsing JSON numbers?<p>It may not be perfect, but compared to the complexity of the XML world and the opaqueness of binary formats JSON is a very pleasant compromise.<p>Shame about it not having comments though.... :-)
robgeringabout 11 years ago
The author suggests using MessagePack, which I hadn&#x27;t seen before but looks really cool.<p><a href="http://msgpack.org/" rel="nofollow">http:&#x2F;&#x2F;msgpack.org&#x2F;</a>
评论 #7398809 未加载
评论 #7398825 未加载
评论 #7398753 未加载
评论 #7398744 未加载
EC1about 11 years ago
&gt;I do not have a magical format to propose to replace it<p>So why did you even comment in the first place?
评论 #7398704 未加载
评论 #7398691 未加载
评论 #7398714 未加载
评论 #7398690 未加载
评论 #7398716 未加载
评论 #7398693 未加载
peteretepabout 11 years ago
<p><pre><code> &gt; * It has to be valid UTF-8, meaning it&#x27;s incredibly &gt; slow to validate. </code></pre> If make basic mistakes about what the format allows, the rest of your comment is liable to be junk.
efuquenabout 11 years ago
&gt; It&#x27;s text-based, meaning it&#x27;s incredibly slow to parse.<p>This is precisely the reason it is used so heavily. Easily readable format to reason about. And <i>incredibly slow</i> is a pretty relative term, when you&#x27;re waiting on database calls or doing other complex logic that is orders of magnitude slower, who cares how &quot;slow&quot; json parsing is.<p>&gt; It has to be valid UTF-8, meaning it&#x27;s incredibly slow to validate.<p>I think being able to embed all sorts of different characters and languages is, again a plus. See argument above about performance.<p>&gt; Its numbers representation is double-precision floating-point, meaning it&#x27;s incredibly imprecise and limited.<p>This argument I don&#x27;t get. I&#x27;m pretty sure I might be missing something, but in my experience you can just put a plain old integer and any parser in any language will extract as an exact integer. Nobody is converting a &quot;1&quot; in json into a double&#x2F;float. Maybe somebody can elaborate and what the author might have actually meant?<p>So, really, the argument all boils down to, it&#x27;s slow and wasteful. Well, while that&#x27;s true I think it&#x27;s pretty much been established time and time again that Moore&#x27;s law has made it possible to value programmer time over CPU overhead, to a reasonable extent (i.e. if the overhead you&#x27;re adding overtakes Moore&#x27;s law and makes infrastructure particularly expensive). If you have a format that is human readable, easy to understand, and simple, that helps tremendously in software development and it would take order of magnitude performance hits to really make it bad tradeoff (and even the, if you weren&#x27;t getting a lot of traffic, who would care?), not just 2x or 3x.<p>We live in a web based world, and that world is fundamentally based on a text based protocol (http) and text based messaging formats. There are plenty of valid and good reasons why it happened the way it did.<p>*Final Note: I would like to see some empirical evidence to compare the wasted CPU cycles and energy that JSON uses compared to if all messages were sent with msgpack or something like it instead. While my own inclination is that number would be dwarfed by the overall energy used in computation I would prefer to see evidence rather then conjecture if you&#x27;re going to make a point like that.
评论 #7398935 未加载
HugoDiasabout 11 years ago
Ok, I understand your argument, now tell me a better format to create an API, Thanks ...
评论 #7398932 未加载
Zikesabout 11 years ago
If msgpack is able to match JSON for serialization&#x2F;deserialization, couldn&#x27;t you make an API in JSON and offer msgpack as an alternative format?
评论 #7400714 未加载
prottmannabout 11 years ago
Here the reasons why i use JSON:<p>* It&#x27;s text-based, meaning it&#x27;s readable and easy to parse.<p>* It has to be valid UTF-8, no hassle with other formats.<p>* Its numbers representation is double-precision floating-point, i can choose what i want.<p>Who cares? Use what you want and what solves your problem at the best way.
Thaxllabout 11 years ago
Servers aren&#x27;t CPU bound anymore, there is no need to worry about that...
评论 #7398991 未加载
评论 #7398747 未加载
jackmaneyabout 11 years ago
Yes, because XML is so much more compact.<p>Oh, wait....
评论 #7398730 未加载
评论 #7398734 未加载
评论 #7398751 未加载
deividyabout 11 years ago
Oh, now that you mentioned it, I&#x27;ll use XML, It&#x27;s very cool and compatible with new technologies, like a new thing of Microsoft called C#.