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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

JSON5 – JSON for Humans

364 点作者 rickcarlino5 个月前

60 条评论

nikeee5 个月前
I think it allows for too much. I was glad that JSON only supports double-quoted strings. It is a feature that removes discussions about which quotes to use. Or even whether to use quotes at all (we still need them for keys with colons or minus in it, so what gives?).<p>The only thing that JSON is really missing are comments and trailing commas. I use JSONC for that. It&#x27;s what VSC uses for the config format and it works.
评论 #42362220 未加载
评论 #42361771 未加载
评论 #42362083 未加载
评论 #42361517 未加载
评论 #42362835 未加载
评论 #42361994 未加载
评论 #42361935 未加载
评论 #42363442 未加载
评论 #42361467 未加载
评论 #42362930 未加载
评论 #42364037 未加载
评论 #42362070 未加载
评论 #42361911 未加载
评论 #42367147 未加载
评论 #42361917 未加载
评论 #42367065 未加载
bawolff5 个月前
As much as i like this (yaml goes way too far, but trailing commas and comments would make json much nicer. I actually think this spec goes too far with single quotes) i hate that it is named json5. I think its unethical to imply you are the next version of something if you don&#x27;t have the blessing of the original author.
评论 #42361256 未加载
评论 #42361263 未加载
评论 #42362128 未加载
评论 #42366232 未加载
评论 #42363170 未加载
评论 #42361212 未加载
yashap5 个月前
I’m a fan of JSON5. A common criticism is “we’ve already got YAML for human readable config with comments,” but IMO YAML’s readability sucks, it’s too hard to tell what’s an object and what’s an array at a glance (at least, with the way it’s often written).<p>When dealing with large YAML files, I find myself frequently popping them into online “YAML to JSON” tools to actually figure out WTF is going on. JSON5 is much easier to read, at least for me.
评论 #42361160 未加载
评论 #42361277 未加载
评论 #42361787 未加载
评论 #42361190 未加载
评论 #42361224 未加载
alex-robbins5 个月前
It&#x27;s too bad EDN [1] hasn&#x27;t seen much adoption outside of the biblical paradise that is the Clojure ecosystem.<p>[1]: <a href="https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Clojure#Extensible_Data_Notation" rel="nofollow">https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Clojure#Extensible_Data_Nota...</a><p>In fact, there doesn&#x27;t seem to be a spec or standard for it, outside of the de facto standard used by Clojure and the programs in its orbit. I guess nobody&#x27;s bothered to write a standard, because the people who are already using EDN are doing fine without one, and the people who aren&#x27;t either don&#x27;t know what it is or don&#x27;t see its value.
评论 #42363075 未加载
评论 #42363193 未加载
bearjaws5 个月前
The whole reason JSON rules the world is because it&#x27;s brutally simple.<p>We already have 5+ replacements that are far more <i>robust</i>(XML, YML) and IMO they are not great replacements for JSON.<p>Why? Because you can&#x27;t trust most people with anything more complicated than JSON.<p>I shutter at some of the SOAP &#x2F; XML I have seen and whenever you enable something more complicated inevitably someone comes up with a <i>&quot;clever&quot;</i> idea that ruins your day.
评论 #42361979 未加载
评论 #42362071 未加载
评论 #42361972 未加载
评论 #42367367 未加载
评论 #42363618 未加载
Zamicol5 个月前
Hijacking for a random concern:<p>I love JSON, but one of the technical problems we&#x27;ve ran into with JSON is that the spec forgot about all special characters.<p>I actually noticed it when reading Douglas Crockford&#x27;s 2018 book, &quot;How JavaScript Works&quot;. The mistake is on page 22.9 where it states that there are 32 control characters. There are not 32 control characters. There are 33 7-bit ASCII control characters and 65 Unicode control characters. When thinking in terms of ASCII, everyone always remembers the first 32 and forgets the 33rd, `del`. I then went back and noticed that it was also wrong in the RFC and subsequent revisions. (JSON is defined to be UTF-8 and is thus Unicode.)<p>Below is a RFC errata report just to point out the error for others.<p>Errata ID: 7673 Date Reported: 2023-10-11<p>Section 7 says:<p>The representation of strings is similar to conventions used in the C family of programming languages. A string begins and ends with quotation marks. All Unicode characters may be placed within the quotation marks, except for the characters that MUST be escaped: quotation mark, reverse solidus, and the control characters (U+0000 through U+001F).<p>It should say:<p>The representation of strings is similar to conventions used in the C family of programming languages. A string begins and ends with quotation marks. All Unicode characters may be placed within the quotation marks, except for the characters that MUST be escaped: quotation mark, reverse solidus, and the control characters (U+0000 through U+001F, U+007F, and U+0080 through U+009F).<p>Notes:<p>There are 33 7-bit control characters, but the JSON RFC only listed 32 by omitting the inclusion of the last control character in the 7-bit ASCII range, &#x27;del.&#x27; However, JSON is not limited to 7-bit ASCII; it is Unicode. Unicode encompasses 65 control characters from U+0080 to U+009F, totaling an additional 32 characters. The section that currently reads &quot;U+0000 through U+001F&quot; should include these additional control characters reading as &quot;U+0000 through U+001F, U+007F, and U+0080 through U+009F&quot;<p>---<p>I&#x27;ve chosen `del` to be my favorite control character since so many engineers forget it. Someone needs to remember that poor little guy.
评论 #42363482 未加载
评论 #42366859 未加载
sethops15 个月前
May I suggest using TOML, which in my experience has been the perfect blend of human readability while having good tooling.<p><a href="https:&#x2F;&#x2F;toml.io&#x2F;en&#x2F;" rel="nofollow">https:&#x2F;&#x2F;toml.io&#x2F;en&#x2F;</a>
评论 #42361518 未加载
评论 #42361320 未加载
rixrax5 个月前
This should have been named NOTjson-somethingv5. Or similar. Now it is far from obvious for the uninitiated that this might not be the &#x27;latest&#x27; version of JSON. And then they end up using this incompatible format by accident, when in all likelihood standard JSON would serve equally well or better in 95% of the use cases.
eknkc5 个月前
I feel like the comments are the only important part. I’d rather not have single quoted strings or unquoted identifiers to be honest. Trailing commas are nice to have though.<p>All I miss in JSON are comments and a native datetime type. Everything else, I’m fine with.
评论 #42361453 未加载
评论 #42361249 未加载
评论 #42362216 未加载
brap5 个月前
Would it be correct to say that this is basically any valid JS code that describes an object, excluding the use of references and function definitions?<p>If not, what is the difference, and why was it made to be different?
评论 #42361540 未加载
评论 #42361369 未加载
bazzargh5 个月前
A common thing in JSON&#x2F;YAML alternatives is to support more types through syntax. I don&#x27;t think this is a good idea. YAML already did this badly with the Norway problem, but JSON also has issues with eg &quot;is it float or int&quot;, what about nulls, what about precision... and so on.<p>There are many, many more types to support and all this does is complicate syntax; the types can be relegated to a schema. For example, where are dates, with or without timezones, what about durations, what about SI units for mass, current, what about currency, what about the positive integers only, numbers as hex, as octal, as base64...<p>One format that _nearly_ gets it is NestedText <a href="https:&#x2F;&#x2F;nestedtext.org&#x2F;en&#x2F;latest&#x2F;basic_syntax.html" rel="nofollow">https:&#x2F;&#x2F;nestedtext.org&#x2F;en&#x2F;latest&#x2F;basic_syntax.html</a> ... which means everything gets ingested as strings, dicts or lists, which vastly simplifies things; my quibbles with it would be it still went for multiple syntaxes (for dictionaries, multiline strings, inline vs multiline dicts&amp;lists. And yet, it still didn&#x27;t make comments part of the data model (which is so useful when processing or refactoring files). While it&#x27;s not perfect, it does separate the validation of scalars, not stuffing someone&#x27;s priority list of validations into incomprehensible syntax.<p>YAML&#x27;s been a decades long mistake and making JSON more like YAML is not the way to fix that.
sod5 个月前
When I manage a project and have the freedom to choose my configuration structure, then I always use typescript. I never understood the desire to have configuration be in ini&#x2F;json&#x2F;jsonnet&#x2F;yaml. A strongly typed configuration with code completion seems so much more robust. Except of course your usecase is to load or change the config via an API.<p>I like what apple is doing with <a href="https:&#x2F;&#x2F;pkl-lang.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pkl-lang.org&#x2F;</a> though.
评论 #42369219 未加载
andreif5 个月前
I think main problem people trying to solve is treating JSON as computer-human interface. It was not designed for it and I don’t think we need to expand its use-case. You can perfectly use subset of YAML with much better readability for human interactions. I wrote custom parsers for subset I need with like 100 lines of Python code. JSON should stay as a loggable system-to-system format that you can render in a more readable way.
评论 #42367378 未加载
评论 #42367421 未加载
Silphendio5 个月前
I find json5 much better than json, but it has still many of the same annoyances.<p>- instead of trailing commas, how about making them completely optional? It&#x27;s not like they are needed in the first place.<p>- curly braces for top-level objects could be optional too.<p>- For a data exchange format, there should really be a standard size for numbers, like i32 for integers and f64 for floats.<p>- parsing an object with duplicate keys is still undefined behavior.
mifydev5 个月前
I don’t know how to feel about this. Personally I want to write configs like code, and I want to avoid using yet another specific DSL for it. So currently working on a tool that allows you to write configs in Typescript - <a href="https:&#x2F;&#x2F;github.com&#x2F;typeconf&#x2F;typeconf">https:&#x2F;&#x2F;github.com&#x2F;typeconf&#x2F;typeconf</a>
jillesvangurp5 个月前
Good API design dictates that you should be flexible as to what you accept and strict about what you serve. Being flexible doesn&#x27;t really break anything.<p>Elasticsearch and Opensearch both actually have partial support for JSON5 (comments), which is a nice feature if you want to document e.g. a complex query or mapping choice. It won&#x27;t return any comments in the response. So it won&#x27;t break other parsers. Implementing JSON 5 support like this is a valid thing to do for any server. More broad support for this in parsers would be nice.<p>I&#x27;d probably enable this on my own servers if this was possible. I&#x27;d need that to be supported in kotlinx.serialization. See discussion on this here: <a href="https:&#x2F;&#x2F;github.com&#x2F;Kotlin&#x2F;kotlinx.serialization&#x2F;issues&#x2F;797">https:&#x2F;&#x2F;github.com&#x2F;Kotlin&#x2F;kotlinx.serialization&#x2F;issues&#x2F;797</a>
评论 #42367345 未加载
epscylonb5 个月前
I&#x27;ve always been a big fan of KDL in principle, haven&#x27;t used it in anger. After that HCL, then YAML, with JSON and others being my least favourite to use.<p>Of course the hard part is gaining enough critical mass to make a significant switch. JSON had AJAX. YAML had Rails. What could make JSON5 or KDL break out?
cute_boi5 个月前
If browser&#x2F;node etc.. starts to support json5, i am sure it won&#x27;t take that much time to get adopted.
ruuda5 个月前
If you&#x27;re looking for a human-friendly json superset (comments, non-quoted keys) that can also abstract away repetitive configuration with variables and list comprehensions, check out <a href="https:&#x2F;&#x2F;rcl-lang.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;rcl-lang.org&#x2F;</a>.
hgs35 个月前
I&#x27;m looking at the JSON5 spec and it appears it does not introduce a capital \U escape sequence for Unicode characters outside the Basic Multilingual Plane (BMP). It&#x27;s not brought up often, but in JSON you do need UTF-16 surrogates to write an escape sequence for Unicode characters outside the BMP. Consider the Hamburger Emoji (U+1F354). Instead of escaping it as &quot;\U0001F354&quot;, you need to escape it with UTF-16 surrogates &quot;\uD83C\uDF54&quot;. This is both cumbersome for humans and not in accordance with the Unicode Standard [1]. It&#x27;s ironic, but many (most?) of the &quot;JSON for Humans&quot; flavors of JSON tend to overlook this.<p>[1] See Chapter 3.8 &quot;Surrogates&quot; of the Unicode Standard.
评论 #42363534 未加载
评论 #42363224 未加载
评论 #42365388 未加载
lambda5 个月前
I find that these efforts to make something that is almost but not quite JSON to be counterproductive.<p>It means that something you can&#x27;t tell if it&#x27;s JSON or another format. You&#x27;ll have some tools that can work with it, while other tools will choke because they expect valid JSON. Oh, someone just switched the quoting style so now your jq based automation is all broken.<p>And now you have to figure out which of these not-quite-JSON formats this is. Is it HuJSON&#x2F;JWCC? Is it JSON5? Does my editor have a mode that supports this particular variant, or am I always going to be fighting with it?<p>And finally, having used HuJSON for Tailscale config: the issue isn&#x27;t just things like comments and trailing commas, or quoting styles. JSON is just a kind of heavyweight and cumbersome syntax for writing config files. I find that I prefer writing a script to auto-generate my Tailscale config, because editing it by hand is cumbersome.<p>There are a number of other possible config file formats, with varying levels of JSON data model compatibility. YAML has its issues, but we&#x27;ve all learned to live with them by now. TOML isn&#x27;t bad, though good luck remembering the array of tables syntax. KDL is pretty nice; it has a slightly different data model than JSON, but it&#x27;s actually one that is somewhat better suited for config files.<p>I&#x27;d rather use any of these for config files than something that is almost, but not quite, JSON.
teddyh5 个月前
I always thought that “JSON5” is a deceptive name. It is not the fifth version of JSON; it is an alternative&#x2F;extension of JSON, of which there are many alternatives, and this one is no more official than any other.
评论 #42362014 未加载
ianbicking5 个月前
I like JSON5 and have used it some. When GPT was younger and I was parsing its JSON output directly, JSON5 was forgiving in useful ways.<p>The one thing I really wish it had was some form of multi-line string, mostly so I could use it with line diffs. Also sometimes for really simple property editors it&#x27;s nice to put the serialization in a textarea, and that works fine for everything but multiline strings.<p>(I suppose you can escape newline characters to put a string on multiple lines, but I find that rather inhumane and fragile)
评论 #42361684 未加载
veesahni5 个月前
This is very close to what the ruby REPL will accept.<p>I tried to paste in the kitchen sink - it didn&#x27;t like dangling decimals and the comment format, everything else worked as expected.
guilhas5 个月前
Hjson looks friendlier for direct manipulation, no string quotes<p>What would be the advantages&#x2F;disadvantages?<p><a href="https:&#x2F;&#x2F;hjson.github.io" rel="nofollow">https:&#x2F;&#x2F;hjson.github.io</a>
评论 #42363166 未加载
efitz5 个月前
If it’s designed for hand authoring it should support an ISO8601 date format; mere mortals cannot author numeric timestamps without tools.
评论 #42363135 未加载
amelius5 个月前
The only thing I worry about is how do you parse this, then modify some fields and write back the file with all the comments still in place?
teilo5 个月前
Or, just don&#x27;t use JSON for config files. There are plenty of human-friendly config file options, so there is no reason to frankenstein JSON in this way.
magospietato5 个月前
Why not just not use JSON for config? In a sane world YAML wouldn&#x27;t even exist and everyone would use something like TOML.
peterkos5 个月前
What is the benefit of this over something like Pkl[0]? Pkl compiles down to JSON, YAML, etc., but the language itself is user-friendly. This way you get best of both worlds: readable and editable for humans, and parsable for computers.<p>[0]: <a href="https:&#x2F;&#x2F;pkl-lang.org" rel="nofollow">https:&#x2F;&#x2F;pkl-lang.org</a>
peterohler5 个月前
There are a few more tolerant versions of JSON. In OjG I called the format SEN <a href="https:&#x2F;&#x2F;github.com&#x2F;ohler55&#x2F;ojg&#x2F;blob&#x2F;develop&#x2F;sen.md">https:&#x2F;&#x2F;github.com&#x2F;ohler55&#x2F;ojg&#x2F;blob&#x2F;develop&#x2F;sen.md</a>
berdon5 个月前
Shameless plug for my JSON&#x2F;5 parser written in zig: <a href="https:&#x2F;&#x2F;github.com&#x2F;berdon&#x2F;zig-json">https:&#x2F;&#x2F;github.com&#x2F;berdon&#x2F;zig-json</a><p>There is a std json library as well but the aesthetics weren’t great imo.<p>The specs are quite pleasant to implement.
AdieuToLogic5 个月前
I find HOCON[0] to be great for this need in JVM-based languages.<p>0 - <a href="https:&#x2F;&#x2F;github.com&#x2F;lightbend&#x2F;config&#x2F;blob&#x2F;main&#x2F;HOCON.md">https:&#x2F;&#x2F;github.com&#x2F;lightbend&#x2F;config&#x2F;blob&#x2F;main&#x2F;HOCON.md</a>
ddgflorida5 个月前
The &quot;official&quot; JSON should be enhanced to cover a few of the pain points.
DrScientist5 个月前
This may be heretical but surely the problem isn&#x27;t lack of comments et al in JSON, rather that people try to use JSON for everything, when it was designed to be a text representation of javascript objects?
评论 #42366538 未加载
eviks5 个月前
&gt; JSON for Humans<p>The emoji in the first paragraph seems to convey the understanding that humans like expressiveness, but the format itself doesn&#x27;t allow Unicode values in keys, which seriously limits said expressiveness...
评论 #42363183 未加载
jwblackwell5 个月前
It feels like AI has made this redundant.<p>I honestly cannot imagine hand typing out some JSON now, or most code for that matter.<p>I just write in natural language what I want and the AI will perfectly output valid JSON.
评论 #42368258 未加载
评论 #42366007 未加载
travisgriggs5 个月前
I wish json had a simple version&#x2F;convention like elixir sigils so I could pass datetimes around as first class entities instead of always having to [de]stringify them.
matt32105 个月前
Yaml is for people, json is for machines
Waterluvian5 个月前
I think the killer feature of JSON is that there’s one version and that won’t ever change. You don’t have to think about compatibility.<p>All JSON is valid YAML. So you clearly can make <i>yet another</i> one of these and make it support JSON. But JSON doesn’t support the stuff you’re adding, so calling it JSON5 just makes things confusing as if it’s a version and not a whole new thing altogether.<p>The ugliest thing the authors could accomplish is making this sufficiently popular that there’s a ton of .json files out there that aren’t actually valid JSON. I hope they’re being careful about strongly discouraging ever writing these outputs to files with a .json filetype.
qwertox5 个月前
Comments are nice. I wonder if they can also be inserted programmatically.
评论 #42361395 未加载
bogota5 个月前
Just use jsonnet if you want this IMO. No need to change json into yaml.
评论 #42362563 未加载
hi_hi5 个月前
Isn&#x27;t JSON for humans essentially YAML? (only kinda joking)
评论 #42361461 未加载
Zamicol5 个月前
I&#x27;m a huge fan. We use it for all our configs.
andy_ppp5 个月前
Unfortunately this is basically that XKCD cartoon about proliferating standards. I think I’d avoid this additional standard and just use JSON or a JavaScript object if I really need this level of flexibility.
c-smile5 个月前
Eh, if you drink, then drink...<p>1. Add `;` as a separator of elements, so you may have:<p><pre><code> { a: &quot;foo&quot;; b:&quot;bar; } </code></pre> 2. Add array tags and space separated value lists so you may have<p><pre><code> { a: 12 13 14; } to be treated as [12, 13, 14] with the tag &quot; &quot;. Normal arrays are parsed with the tag &quot;,&quot; </code></pre> 3. Add &quot;functors&quot; as, again, tagged arrays<p><pre><code> rgb(128,128,14); will be parsed to an array with the tag &quot;rgb&quot;. Also you may have calc(128 + 14); </code></pre> 4. Add tagged numbers so<p><pre><code> 90deg will be parsed as a number with the tag &quot;deg&quot; </code></pre> And you will get pretty much CSS that is proven to define quite complex constructs with minimal syntax.
righthand5 个月前
` leadingDecimalPoint: .8675309, andTrailing: 8675309.,`<p>Sorry but what is the benefit of this? Lazy shorthand? This is too much. Is this a string in other languages? PHP the `.` is a string concat.
up2isomorphism5 个月前
No I don’t need this thing.
stickfigure5 个月前
Still no timestamps :-(
评论 #42361931 未加载
评论 #42362551 未加载
评论 #42361993 未加载
michaelcampbell5 个月前
Looks very nice, but I feel it&#x27;s one of those &quot;yeah, it&#x27;s better, but only useful for personal projects, or until it gets critical mass which won&#x27;t be until after I&#x27;m dead, if at all&quot; projects.
ultimoo5 个月前
can this be used to convert llm output to json?
lolive5 个月前
JSON6 will feature triple-quote string quoting. Either made out of “ or ‘. Wake me up when it happens. PS: quoting line returns for multiline sounds weird. But who am I to comment…
counterpartyrsk5 个月前
KISS
Pxtl5 个月前
It&#x27;s infuriating that we&#x27;re still struggling with this after so many years.<p>Every time I learn a new format I want to scream &quot;why can&#x27;t you be normal?&quot;
评论 #42361989 未加载
评论 #42362349 未加载
rk065 个月前
Now, it would be great if we have parsers, editor plugins and json schema supprot as well.<p>until then, jsonc works for me
lakomen5 个月前
Oh he&#x27;ll no not another standard no one needs. JSON is good enough
112358132134555 个月前
only needs trailing commas
655 个月前
Why not just use YAML at that point?
hoseja5 个月前
Hey look another xkcd:&#x2F;&#x2F;927
mariocesar5 个月前
Isn&#x27;t this simply YAML but with curly braces?<p>Another thing is that It feels wrong to have comments in JSON, like allowing comments in CSV files.