TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Nobody gets fired for picking JSON, but maybe they should?

44 点作者 maximilianburke5 个月前

17 条评论

buzzardbait5 个月前
The complaint is mostly about JSON parsers, not the JSON spec itself, which as other comments have said works quite well in practice.<p>In .NET land the most popular JSON library is Newtonsoft which plays fast and loose with the JSON spec and makes a lot of default assumptions. A couple of years ago Microsoft rolled out their own first-party JSON library, which is a lot stricter and requires the developer to explicitly configure the parser instead of making assumptions.<p><a href="https:&#x2F;&#x2F;learn.microsoft.com&#x2F;en-us&#x2F;dotnet&#x2F;standard&#x2F;serialization&#x2F;system-text-json&#x2F;migrate-from-newtonsoft?pivots=dotnet-9-0#table-of-differences" rel="nofollow">https:&#x2F;&#x2F;learn.microsoft.com&#x2F;en-us&#x2F;dotnet&#x2F;standard&#x2F;serializat...</a><p>But some developers still instinctively reach for Newtonsoft, even when working on brand new projects. In practice, this sort of ingrained habit is far greater of a problem than the JSON spec itself.<p>The author says that Protobuf makes all of JSON&#x27;s problems go away. I don&#x27;t know enough about Protobuf to confirm or deny, but I know that it&#x27;s not tested 10 trillion times a day like JSON is.
评论 #42389723 未加载
评论 #42387622 未加载
评论 #42386879 未加载
评论 #42390296 未加载
评论 #42392191 未加载
评论 #42394561 未加载
solidasparagus5 个月前
I appreciate the blog post and I learned a bunch from it!<p>But the quote that comes to mind is: &quot;People who say it cannot be done should not interrupt those who are doing it&quot;<p>It&#x27;s quite a stretch to say that JSON is broken and can&#x27;t be fixed. JSON works exceptionally well in practice and any review of it that fails to acknowledge this is, IMO, very lacking in perspective.
评论 #42388362 未加载
the_cramer5 个月前
I feel like many of the points are complaining about the parsing side of JSON. Not the format itself. You can argue that a format is useless when &quot;everyone&quot; parses it &quot;wrong&quot; but no specification on this earth is free of that.<p>Using a lot of json in our API space and it working fine (so far) leads me to think that OP complains about something that does not fit their use-case.<p>Firing people for choosing something that does not fit &quot;your&quot; use-case seems like a wild take.
评论 #42388573 未加载
评论 #42386435 未加载
catlifeonmars5 个月前
Go can actually decode numbers into an “arbitrary precision” raw token (json.Number, which is a wrapper around []byte). You can turn this on at the decoder level or for a particular field. I often do this for more fine grained control of number decoding without needing to drop to the tokenizer.
s6af7ygt5 个月前
I agree with all of the points, except the last. Protobuf is a nice transfer format but it&#x27;s horrible once a human wants to inspect or copy&#x2F;paste a payload.
评论 #42388087 未加载
Sohcahtoa825 个月前
This article reeks of being written by someone with maybe a year or two of experience that&#x27;s read someone else&#x27;s ill-informed rants about JSON and is rehashing it.<p>IMO, the only valid complaint is that the JSON spec can&#x27;t handle Inf or NaN, but I&#x27;d argue that if you&#x27;re finding yourself dealing with Inf or NaN, then you likely have a bug elsewhere, and JSON is merely exposing it.<p>If you&#x27;re storing credit card numbers, license keys, barcode IDs, etc. as integers, <i>you&#x27;re already doing it wrong</i>, and what serialization format you&#x27;re using is completely irrelevant.
评论 #42448966 未加载
评论 #42394427 未加载
AtlasBarfed5 个月前
Jason can&#x27;t be streamed: wtf? If you have a data connection that can be broken, every data format is incomplete until the last ack<p>There is absolutely nothing stopping you from parsing json as it comes in. An open array that hasn&#x27;t reached the closing arrays character yet? How is that different than a stream of data elements?<p>With the Jackson API, I was easily able to parse incoming text into Json tokens and extract data as it came in. I did this for certain corner cases where Json documents possibly were sent in that were greater than could be practically put into memory.<p>Sure, you might want to have a rollback function in case there is a break in the data transfer, but how&#x27;d that be different with a different data format streamed?<p>The guy is complaining a lot about number formats. If you care about it that much just put your numbers and strings, and make the parsing format part of the standard &#x2F;api interface.<p>This guy simply appears to be in love with binary formats and strong typing. If that floats his boat by all means do it.<p>The fact that so much of the web relies on Json, and it pretty much seems to work. The guy hopefully indicated some corner cases on its use. But come on it&#x27;s not fatally flawed.
评论 #42390332 未加载
dzaima5 个月前
Much as JSON is without a doubt far from perfect, I think most of the article is rather meh.<p>Protobuf won&#x27;t stop people from trying to put a license keys, card numbers, or other IDs in a 64-bit float or int. All it&#x27;ll do is make someone be able to smugly point to a certain person and say &quot;you&#x27;re stupid, you did this incorrectly as per the spec&quot;. The extra assurance could even make things worse, e.g. using 64-bit ints for credit card numbers and having something break that interprets it as a signed int (or perhaps become unusable if 20-digit numbers happen), or have code that converts it to a float anyway, devolving back to 53-bit precision. The &quot;fix&quot; for both formats for normal people is still exactly the same - &quot;please please please don&#x27;t put things that aren&#x27;t strictly counts of things or imprecision-tolerant real numbers in number types&quot;.<p>Unpaired surrogates is just a question of which component fails. If any! An arbitrary user input containing an unpaired surrogate would likely be better off quietly transformed (or preserved) than become a DoS vector.<p>Lack of NaNs, infinities, and compact ways to encode arbitrary bytes are the things I personally find the most unfortunate. The special constants are especially weird as null&#x2F;false&#x2F;true exist, but byte strings do have the problem that not all languages have a reasonable distinct thing for such to map to.<p>A funky side-note is that JSON being so tolerant&#x2F;imprecise (and as such most suppliers not pushing it to edge-cases) means that crappy parsers&#x2F;producers aren&#x27;t typically particularly problematic, though this perhaps isn&#x27;t really a thing to judge data formats by.
avmich5 个月前
&gt; Protobuf, however, has none of these problems<p>I like this optimism :) .
exabrial5 个月前
I wish json docs had a schema you exchange for your objects, and evaluate compliance against the schema.<p>XSDs one of the only redeeming qualities of XML.
评论 #42390209 未加载
评论 #42387855 未加载
评论 #42387872 未加载
Glyptodon5 个月前
I think in many cases people are just using JSON because they are getting it for free, not because they actively picked it.
jendjcneeb5 个月前
As many have said, the post is complaining about broken parsers and broken data structures, not a broken spec.<p>An example for this is using a map instead of a key-value-list for object representation<p>Or float instead of arbitrary precision decimals<p>Are there more broken json libraries out there, then there are broken XML libraries?<p>Maybe. But that&#x27;s not a problem with the spec. Choosing JSON if your use case is well suited is fine nevertheless<p>Just don&#x27;t use obviously broken libtaries
评论 #42393647 未加载
scotty795 个月前
I really love the minimap idea on this website. I think it&#x27;s the first time ever that I see it.
lakomen5 个月前
Or maybe they shouldn&#x27;t
p4cmanus3r5 个月前
PHP sucks too
评论 #42388841 未加载
dainiusse5 个月前
s&#x2F;JSON&#x2F;YAML&#x2F; :)
nijave5 个月前
s&#x2F;JSON&#x2F;CSV&#x2F;