14 ms·
Fixing JSON
- donpdonp 10y agoOne way to get a comma-free JSON-like format is to write the document in hjson, which is a superset of JSON. http://hjson.org/ http://hjson.org/ var config = HJSON.parse(fs.fileReadSync('config.hjson')) Another more obscure, and more powerful serialization format that does away with commas (commas are treated as whitespace!), has a date type, and much more is Rich Hickey's (of Clojure fame) EDN. https://github.com/edn-format/edn https://github.com/edn-format/edn {:a 1, "foo" :bar, [1 2 3] four}
- wesleytodd 10y agoPersonally I would rather it require trailing commas like Go does, any optional syntax is a step backwards IMHO
- ambrop7 10y agoThe best way is to require one comma between elements but allow one trailing comma after the last element. This way you can both do multi-line and one-line lists nicely.
- greenyoda 10y agoI never understood why the double quotes around property names are mandatory. For example, in JavaScript, I can write { foo: 1, bar: 2 } but JSON syntax insists on { "foo": 1, "bar": 2 } This makes JSON less easily readable by humans, and harder to write or edit by hand. Anyone know why JSON was designed this way?
- shill 10y agoMy assumption is that quotes are needed for keys with spaces. > x = {} > x["foo bar"] = 1 > x { 'foo bar': 1 }
- Retra 10y agoThat only explains why they are permitted, not why they are mandatory.
- xrstf 10y agoBecause using certain keys could break your JavaScript (and JSON was designed to be a subset), like { delete: "me" } If you don't want to keep a list of known keywords around, just insisting on quotes is the easier way. [EDIT: See also this YouTube video, where Douglas Crockford explains it himself: https://youtu.be/-C-JoyNuQJs?t=5m https://youtu.be/-C-JoyNuQJs?t=5m]
- yepperino 10y agoUnquoted keywords are valid ES5.1 object properties. alert(JSON.stringify({delete: "me", for: 1, var: 2})); results in: {"delete":"me","for":1,"var":2} The only browser it does not work in is IE8 and earlier.
- lucian1900 10y agoJSON significantly predates ES 5.1
- jerluc 10y agoI'm no expert, but I'd imagine fully dropping the quotes wouldn't allow you to use the same syntax as a map/dictionary in Javascript, whereby the keys could be [almost] any type, and string keys could contain characters such as - or even : which otherwise would prove ambiguous to a Javascript parser.
- nemild 10y agoI don't know the history of why design decisions were made in JSON, but one might be the allowance for spaces in keys and mirroring the usage within arrays (where commas and spaces may be used in a string, but shouldn't be confused with a record separator). Per my other comment, there are a variety of plugins on the editor side that will make JSON look like this (e.g., vim-json ). To write out to JSON from that format, you can obviously just write a plugin (in JS this is one line).
- Feneric 10y agoThe stricter syntax allows JSON to be directly parsed outside of JavaScript in other languages like Python. This is a nice feature and one of the selling points of JSON.
- usrusr 10y agoJSON values low variance between different representations of logically equivalent documents. It's not a primary concern (e.g. the explicit lack of key order allows a lot of variance), but it seems to trump syntax convenience just about everywhere except whitespace. Going all unquoted-keys would also be low variance, but this would restrict keys from "any string" to "valid javascript identifiers" or something bespoke in between.
- dlbucci 10y agoAt this point, I'd settle for JSON5 (http://json5.org/ http://json5.org/), which says any JSON that's a valid ECMAScript 5 object is valid JSON (including trailing commas, unquoted keys, single quote strings, and comments). I don't think it's very popular at this point though, but I guess I've never tried to use it.
- veesahni 10y agoThis is a good idea. Also browser makers won't feel like they're supporting another format. It's just a modernized version of JSON.
- colanderman 10y agoUgh no. Adding all that crap complicates writing a correct parser. JSON's value is in that it is easy to parse. If editing JSON is your problem, use a better editor. If you really want to use JSON as a config file format, use something like YAML instead.
- majewsky 10y agoOr TOML, if you find YAML's syntax too messy.
- nemild 10y agoTwo quick observations: - Getting standards passed is hard (especially for popularly used standards), but can be supported by latent usage in the community. You can create a plugin for a few languages that automatically allows the timestamps and doesn't require commas. Get a bunch of people using it, and you'll be on your way to actually getting it in the standard in the future (still debatable in this specific example, but broadly, usage never hurts for getting something into a standard) - If your concern is your own frustrations (rather than benefits of the vast majority of people) - I highly recommend a simple editor-level mapping that translates from your preferred DSL to the underlying standard
- lhopki01 10y agoJust use yaml?
- wtetzner 10y agoOr if you still want something easy to parse, s-expressions.
- omginternets 10y agoCould you please elaborate? I'm vaguely familiar with S-expressions from my cursory inquiry into lisp (planning to take the plunge in November), but I don't see how they can be applied in this context.
- nv-vn 10y agoS-expresions are really just a way of representing a tree of data (in Lisp code, the S-expression literally represents the abstract syntax tree that is used for the code). Take the JSON example: { "IDs": [116, 943, 234, 38793], "Settings": { "Aperture": 2.8, "Shutter speed": "1/250" } } You could rewrite this as an S-expression as: ((IDs (116 943 234 3879)) (Settings (Aperture 2.8) ("Shutter Speed" "1/250")))
- omginternets 10y agoThanks! I figured it would be simple, and indeed it was :)
- moogly 10y agoYAML is not as simple as one might think. The spec[1] is 80 pages long after all... 1: http://yaml.org/spec/1.2/spec.pdf http://yaml.org/spec/1.2/spec.pdf
- detaro 10y agoI feel like YAML might be a bit to complicated in the other direction, with many ways of encoding quite complex things and the connected risk for bugs. (E.g. the Python-binding, pyYAML, can't even read its own output correctly in all cases)
- emilsedgh 10y agoMajor irritant: Commas I thought the major irritant was having to add double-quotes around keys? Commas never bothered me personally, but having to use double quotes is actually irritating.
- espadrine 10y agoIt comes from the flow of edition: remove the last element of a list (which typically is on its own line), forget about the fact that there is a comma at the end of the previous line. But both optional commas and optional double-quotes are provided by Hjson <https://hjson.org/> https://hjson.org/>. They do not advocate its use in protocols, however.
- smcl 10y agoI was thinking the same thing - maybe I haven't hand-edited enough JSON but I have never felt like commas were any sort of issue at all
- oxplot 10y agoInability to add trailing commas creates two problems: - You can forget to drop/add comma when copying an existing line - Adding/Removing last element shows up as two changes in diff
- tootie 10y agoIf you did all of that you'd still fall way short of what you have been able to do with XML for probably 10 years. XSD defines structure in terms of inheritance, composition, strong types, numerical ranges, enumerations, referential integrity, namespaces.
- stouset 10y agoRaise your hand if you miss hand-editing or reading XML.
- oconnore 10y agoRequiring that a markup language (that must be sent across the wire between multiple buggy parser implementations) be hand editable is a recipe for disaster, and will never be as flexible as building/modifying an appropriate AST in a scripting language. There's not even a good reason to read HTML anymore. You hit Ctrl+Shift+C in Firefox (or I think it's J in Chrome) and you view the actual machine-parsed DOM structure. The only reason human-editable/readable formats were ever necessary is a lack of appropriate dev tooling.
- kuon 10y agoI have to agree, I've been working with JSON for 10 years and nearly never touched JSON by hand.
- tootie 10y agoRaising hand. If your IDE understands XSD, it is far easier to do than JSON. Tab completion on all your fields and instant validation of values.
- DonHopkins 10y agoI'm sure Tim Bray would have some opinions on that.
- alayne 10y agoThose things aren't a goal or desired feature of most JSON use. There's a reason people hated SOAP. XML is better suited for documents. For everything else, XML doesn't work very well.
- _greim_ 10y agoWith the exception of trailing commas, all these things would break the fact that JSON is a subset of JavaScript. Breaking that would cause a lot more problems than it solves. It's just that the minor problems you have to live with seem worse than the major problems you don't.
- wtetzner 10y agoWhat value is there in having JSON be a subset of JavaScript? In fact, it would be a good idea to make it not be a subset of JS, because that would prevent people from evaling it.
- doppel 10y agoMost major browsers now support non-eval JSON parsing that it's a moot point - but it still requires it to be valid JSON, also be be usable in javascript out of the box. JSON has the same thing going for it as the h.264 video codec - it may not be _the_ best/most open/etc. format around, but it is one of the few that is supported out the box by all major browsers and Just Works™ (with it's shortcomings).
- wtetzner 10y agoSure, but there's a difference between "we shouldn't break an existing format" and "it has to be a subset of JavaScript".
- fractaled 10y agoIt wouldn't be JSON then. Give this new thing a new name and move on.
- wtetzner 10y agoTo be honest, I agree that there's really no point in changing JSON. I do think there's value in using something other than JSON.
- captainmuon 10y ago
- ambrop7 10y agoTwo more issues: - No support for comments. - No support for NaN and Infinities (i.e. lack of full mapping to IEEE 754). Also at least on Chrome, JSON.stringify(-0) gives 0, though JSON.parse("-0") does give -0. Weird.. As far as schemas are concerned, I find it nicer to not use schemas but access the JSON through an interface that checks things on the fly (types, existence), effectively verifying the JSON while you're examining it. E.g. things like x.get_int('name'), which throws exception if it doesn't exist or isn't an integer. Possibly even with an error message explaining where exactly and what is wrong (like: foo.bars[4].bazes["abc"]: attribute "qux" does not exist).
- ksherlock 10y agoThe original JSON spec included comments. They were removed because people were using them as processing directives.
- otterley 10y agoI'm not sure how dropping comma separators would work in practice, because carriage returns aren't required between array or hash elements in JSON. So this would also have to be legal: { "foo": "bar" "baz": "quux" } I'm not sure that's better, personally. It's also syntactically invalid in Javascript: > "bar" "baz" SyntaxError: Unexpected string
- idunno246 10y agoLet's just remove periods from sentences to They clearly aren't needed since there's a capital letter there If anything I'd rather trailing commas in lists be defined as valid, and separation there is useful like you say
- hutzlibu 10y agoYou could use "line-break" instead - but I also don't see really the point in removing comma's in the first place.
- outsidetheparty 10y agoShameful confession: when I was first introduced to JSON, I was convinced it would go nowhere. "XML already does everything JSON does! And there's no way to differentiate between nodes and attributes! And there are no namespaces! And no schemas! What's the point of JSON?" And a couple of years later I looked up from the tangled mess of XSLT I was working on to discover that the rest of the world had moved on. JSON is just javascript, and it leaves out everything else. That's its entire reason for existing, and it caught on because that's all that 99.44% of anyone needed. Timestamps you can add today, without changing the protocol; just put them in your data if you need them. So I'm not sure what he's even proposing there. Schemas: OK, he doesn't like JSON Schema's anyOf. Fair enough. There's no real proposal here for how to fix it, so not much to say here. Replacing commas with whitespace sounds to me like replacing a very minor irritant with a constant full-body rash. Stuff like his example of "IDs": [ 116 943 234 38793 ] would lead to far more confusion and errors than the occasional stray trailing comma. So I guess I pretty much vote no on this one thanks for asking
- rkrzr 10y ago"Timestamps you can add today, without changing the protocol; just put them in your data if you need them. So I'm not sure what he's even proposing there." He is proposing to add a timestamp type to the grammar. This would have the advantage that there would be one canonical way to have timestamps in your JSON. It would also mean that the parser would already validate them for you and you would not have to do that yourself every time. I definitely see value in that.
- geezerjay 10y ago> He is proposing to add a timestamp type to the grammar. This would have the advantage that there would be one canonical way to have timestamps in your JSON. There is already a canonical way to have timestamps: encode them as defined in RFC 3339. Done. The proposals add nothing to JSON and don't make sense. I mean, screwing up with the language just to add a very specific data type that is used in only a specific corner case that isn't even supported in the use case that's provided as an example? Nonsense.
- philsnow 10y agoIf you're going to drop the commas in the dictionary definitions, why not drop the colons too? { "key" "value" 42 37 } It's a rhetorical question; I think removing the commas is a bad idea. Troubles while hand editing json shouldn't be an overriding use case that drives the syntax. All of those complaints about json and nothing about how you can't have comments?? I feel like Tim Bray and I aren't even on the same planet.
- underbluewaters 10y agoCommas aren't a huge deal for me personally but if there were to be a "json2", dealing with them and removing the double-quoting requirement for keys would make authoring a little easier. Ultimately these are issues that are easily solved with a linter though. A standard date type would be huge however, and I'll add to that built-in support for comments. These two things would expand the scope of what you could do with JSON. JSON is already used in so many places for config files but without comments it can be a poor choice.
- ebbv 10y agoDude really? Commas are not a big deal and you're talking about a major change to get rid of them; making white space matter. Currently white space doesn't matter. In order to get rid of commas it has to. That should not be glossed over or treated lightly.
- susan_hall 10y agoDave Winer's remark from 2006 offers some historical perspective: "I've been hearing, off in the distance, about something called JSON, that proposes to solve a problem that was neatly solved by XML-RPC in 1998, the encoding of arrays and structs in a format that could easily be processed by all programming languages. The advantage being that you could easily support the protocol in any language that supported XML and HTTP, which, at the time, was quickly becoming all languages." http://scripting.com/2006/12/20.html http://scripting.com/2006/12/20.html Then there was someone, much younger than Dave Winer, who wrote a response to this (during 2006), and who said (paraphrase) "When I'm older, I look forward to my XML moment; my horror at something that the young kids are doing." I wish I could find that second quote, but I worry it is lost in the mists of time.
- andreygrehov 10y agoI'd argue that getting rid of commas would lead to an error-free experience. Say I use UUIDs: { "884fbf28-b285-49c2-8335-e42aa3fc896d" "f08bc223-2b49-4d49-a308-7bb93691cef8" } vs { "884fbf28-b285-49c2-8335-e42aa3fc896d", "f08bc223-2b49-4d49-a308-7bb93691cef8" } Another example is long ids: { 214748364721474 89234789 7248374293843 23874827 } vs { 214748364721474, 89234789, 7248374293843, 23874827 } Should we take into account text format and things like font-spacing? I say yes, because user experience is what's valuable here. Edit: formatting
- Kequc 10y agoThe proposal doesn't fix JSON it introduces an entire new format. One which I would not be able to use without a 3rd party library that parses it. If I'm already using JavaScript that is one of the many benefits it has in the first place. Timestamps are easily included when I want them, I tend to prefer UNIX time as it's just so much more impact proof. With this proposal can I use UNIX time if I want? I don't have any problem with JSON. If I did I would have a problem with JavaScript itself, and while there's plenty to complain about I wouldn't propose mixing more formats into it as a solution. There isn't enough care being taken not to introduce additional complexity into the JavaScript world.
- drawkbox 10y agoWhile I respect tbray we need to fix engineers that try to 'fix JSON', absolutely nothing is broken with JSON. It is nearly a perfect spec for the role it plays. It has taken off because it is so simple. I am constantly amazed that something so simple keeps being jabbed at with more complexity by engineers. The job of an engineer is to make things that are complex simple, JSON did just that. Make a new standard for your fixes and watch them spiral out of control like XML. Making a simple format that works is damn hard and JSON is a nearly flawless attempt. It is baked into the ecosystem so let's not break it. It was a response to XML complexity/verbosity for use in javascript first, it is so damn useful that it is used everywhere now, why? simplicity. Everything you need can be done with current JSON. Dates in quotes or ticks (another key for offset if need be), comments in separate files (do you really want © Oracle or Microsoft in all your data files?), strong typing GTFO (use a schema if verbosity is needed -- it supports all needed base types string, numeric, list, object), and it is Javascript Object Notation so it's purpose was to tie to Javascript, don't even attempt to break it from Javascript. If you need more use YAML or XML or a new standard. If you are trying to change JSON, back away slowly, go add your complexity for minimal or worse benefit elsewhere...
- deleted 10y ago[deleted]
- b34r 10y agoRemoving commas makes minification less useful.
- athenot 10y agoCommas irritate me too. But I think removing them from The Serialization Format Known as JSON is a mistake. My workaround is to use CSON, since I'm already using CoffeeScript. It add the syntactic sugar where I'm hand-editing JSON, yet it doesn't impose my tastes on the rest of the world.
- booleanbetrayal 10y agoI miss AS3.
- Jizzle 10y agoHand-editing JSON may not be the most important way of interacting with it... In that case, the arguments in favor of breaking long-established compatibility for the sake of hand-editing should be particularly strong. If personal forgetfulness about editing around commas or date strings are strong arguments, then they should surely also apply to every programming language that uses commas or lacks the concept of a date literal. After all, the code of programming languages exists to be edited, and JSON is merely a means of serialization.
- ivanhoe 10y agoTimestamps should include timezone offset.
- lttlrck 10y agoHis example uses RFC3339 which does include timestamps.
- niftich 10y agoI know this is from Tim Bray, one of the primary authors and/or maintainers of XML, RDF, Atom, and JSON, but while I too find some annoyances with JSON, I accept them because: - JSON was never designed to be hand-editable. It's a lucky accident that it's more palatable to edit than XML, but there are other formats like YAML, TOML, and even .ini that fulfill that purpose. - While JSON was originally envisioned as a subset of Javascript and intended to be materializable by JS eval(), this very quickly turned out to be a bad idea. Once we all switched to using parsers, there is no more compelling need to remain compatible with Javascript, other than human recognizability of syntax, and, y'know, compatibility with 'old' JSON; and - JSON's greatest strength is that it has such a good impedance match to native 'abstract' data structures supported in just about every contemporary programming language: strings, numbers, lists, maps. When people say 'simple', I don't disagree, but I'm convinced they're actually referring to this feature. Adding additional types -- yes, even timestamps -- would break this property, as datetime handling in most languages leaves a lot to be desired.
- joshstrange 10y agoThe first language that comes to mind when I hear "datetime handling in most languages leaves a lot to be desired" is, slightly ironic considering JSON's origins, javascript. If you ever touch a date in JS you HAVE to pull in something like moment, full stop. JS Date is a steaming pile of shit.
- nevi-me 10y agoTo go on a tangent, Java8 dates are "awesome" if you've used Joda-Time before, for the rest of us it's a pain in the backside. I found myself spewing lots of code to just do Moment one-liners. That made me appreciate Moment much more, to the extent that I sometimes just eval a Moment script with Nashorn at times. On the JSON part, I agree with everyone, my go-to language for most things is JavaScript, and I'm okay with dates in JSON. I think it's RFC3336 as everyone says (2016-08-20T21:12:26.231Z). Date parsing could be better when moving across languages, but I mostly prefer sending around millis since Epoch. Considering that people mainly look at their JSON for debug purposes, anyone seeing 1471727663538 should recognise that it's a date. Other commenters put it well that the author should rather propose a new language, JSON is fine the way it is. Typed successors like Protobufs don't have native date parsing, but I guess being binary, they take away the commas too. I'm comfortable hand-writing JSON or editing it when needed. Most text editors help out by highlighting errors and keeping track of parentheses.
- rurban 10y agoMandatory double-quotes for keys just to get rid of required commas does not make it better. There are better relaxed JSON's available than this one: * https://hjson.org/ https://hjson.org/ does not need those double quotes and can handle without commas just fine. * https://github.com/phadej/relaxed-json https://github.com/phadej/relaxed-json also allows comments, trailing commas, simplier strings as in YAML. * RJSON http://search.cpan.org/~miko/JSON-Relaxed-0.03/lib/JSON/Relaxed.pm http://search.cpan.org/~miko/JSON-Relaxed-0.03/lib/JSON/Rela... is similar.
- cies 10y agoJSON is not optimized to be written by humans (I'd argue even JS is not well optimized for that </joke>). There are other formats for that, like YAML and TOML[1]. When JSON is needed for human-to-computer stuff, I'd say TOML is pretty much always a better choice. A common use case for TOML is config files. And I see a lot of config in JSON lately; this makes me sad. (Though not as sad as the config-in-XML thing the Java ecosystem suffered from.) 1: https://github.com/toml-lang/toml https://github.com/toml-lang/toml
- nerdponx 10y agoTOML is a good idea. Maybe it will catch on and sometime within this decade we will finally have a standard format for config file </wishfulthinking>
- crdoconnor 10y agoTOML is kinda ugly compared to YAML.
- ymse 10y agoYAML is a pain to parse. And as a human, having to remember quoting string values like "yes" and "on" to prevent them from being interpreted as booleans in YAML really grinds my gears. I don't care if it's prettier; YAML can't disappear quick enough. I wrote a haiku some years back to demonstrate how broken the Ruby implementation was. YAML: takes a no for a 'no': no spring,summer,fall,winter: 3,6,9,12 the game is: on Running it through ruby 2.3.1 yields.. {"YAML"=> {"takes a no for a 'no'"=>false, "spring,summer,fall,winter"=>36912, "the game is"=>true}}
- crdoconnor 10y agoI agree. That's partly why I wrote this: https://github.com/crdoconnor/strictyaml https://github.com/crdoconnor/strictyaml e.g. >>> load(x, Map({"YAML": MapPattern(Str(), Str())})) {'YAML': {'spring,summer,fall,winter': '3,6,9,12', "takes a no for a 'no'": 'no', 'the game is': 'on'}} >>> load(x, Map({"YAML": Map({"spring,summer,fall,winter": Str(), "takes a no for a 'no'": Bool(), "the game is": Bool()})})) {'YAML': {'spring,summer,fall,winter': '3,6,9,12', "takes a no for a 'no'": False, 'the game is': True}}
- amyjess 10y agoJSON is fine for what it was intended to be: a way to serialize fundamental data structures to disk or over the network. If you want something optimized for human editing, such as for a configuration file or a DSL, we already have YAML for that. Hell, JSON is a valid subset of YAML, so you don't even need two parsers.
- alayne 10y agoYAML including the entirety of JSON is not a positive argument in favor of YAML.
- mschuster91 10y agoI don't agree with the "timestamps" part, for several reasons: 1) the author does not mention in his example the use of timezone offsets (which are a part of RFC3339), that's a bit irritating 2) Timestamp parsing and emitting sucks, no matter the language, because the format specifiers are wildly inconsistent across platforms. I prefer the good old UNIX timestamp, because with it there's no complex massaging needed in order to operate with the timestamp. Also, the author is missing comments entirely - no matter if shorthand // or long-form /* */ gets included, JSON desperately needs commenting ability; but on the other hand I'm worried about compatibility with older systems...
- pluma 10y ago1) The author does. Z means UTC. 2) The JS Date type has a "toISOString" function that emits an ISO date time string like the ones used in the examples. Since everything else is already based on what JS does, why not just move that behaviour into the JSON spec as well?
- JBiserkov 10y agoJSON was fixed in 2014: http://blog.cognitect.com/blog/2014/7/22/transit http://blog.cognitect.com/blog/2014/7/22/transit https://github.com/cognitect/transit-format https://github.com/cognitect/transit-format
- MrBuddyCasino 10y agoSounds nice, is anyone using it? Is it somewhat readable by humans?
- cocktailpeanuts 10y agoI don't know who the OP is but I'll assume he's an authority in JSON since he talks about how he wrote some RFCs and stuff. Anyway this is why I think there should be a better way to move tech standards forward than leaving it up to some small number of people who are way too ahead of the curve that they think everyone else has the same problem they do. In my opinion there is nothing wrong with commas. I am sure the OP had his own issues while working too much with JSON, but for the 90% of the population it's not a problem and even a better way to represent data. As an example, [116, 943, 234, 38793] is 100% clear and intuitive. Anyone who has seen any array representation will get what this means. But change it to [116 943 234 38793]? There are so many ways you can interpret this. I guess the only people who would think this is better than the 100% intuitive [116, 943, 234, 38793] option are JSON nerds who think too much about this (and when I say JSON nerds I don't mean JSON "users", but people who try to come up with the standard) As someone who really hates what's going on with javascript (with all the new syntax that needlessly sacrifices simplicity and intuitive nature for the sake of making things shorter), I can't really think nicely about these opinions. I think these standards that are used by a huge population should move forward in a more democratic way. Or at least let more "normal" people make the decision.
- MrZongle2 10y agoThe author, Tim Bray, is one of the co-authors of the XML specification; https://en.wikipedia.org/wiki/Tim_Bray https://en.wikipedia.org/wiki/Tim_Bray
- gsmethells 10y agoJust turn it into a Python dict already. ;)
- dastbe 10y agoAnecdotally, I've really enjoyed using ION[0] at Amazon. It has all of the features the OP wants, besides semantic whitespace which I'm not a fan of. [0] http://amznlabs.github.io/ion-docs/index.html http://amznlabs.github.io/ion-docs/index.html
- DCoder 10y agoRegarding timestamps, the at-sign is already used by GNU tools, as a prefix to indicate actual UNIX timestamps (seconds since epoch): https://www.gnu.org/software/coreutils/manual/html_node/Seconds-since-the-Epoch.html#Seconds-since-the-Epoch https://www.gnu.org/software/coreutils/manual/html_node/Seco...
- philliphaydon 10y agoJSON isn't broken. There isn't anything to fix. :/
- adrianratnapala 10y agoI agree with those who say JSON should never change, but should one day be replaced. It behooves us to think about what that replacement should be. My own peeves: * Numbers are stored in decimal but usually interpreted as binary with no guidance about rounding. * The concatenation of valid JSON blobs is never valid JSON. * The empty string is not valid JSON. The last two can be "fixed" by a format called "arraySON" where the global blob represents not a JSON object (dictionary), but the contents of an array plus an optional trailing comma. Or given some of the ideas on this thread, perhaps a manadatory leading comma.
- xvolter 10y agoI'd see a trailing or leading comma as a potentially null, or undefined. It's intentionally against spec. I personally see the concatenation an issue in particular with streaming. Streaming JSON objects and parsing them on the fly is a pain, usually requiring a SAX parser. To concat two objects though, I feel like you could just merge the two, if you are okay with appending two arrays, if you had to merge two JSON objects you could. Numbers I seen issues with, I've had to store numbers as strings before, there is guidance however, the official ECMA-404 spec for JSON says there can be any number of digits following a "." in numbers, then optionally followed by an "e", "+" or "-" and more digits. For parsing then, it would be limited by the data types available to the parser. Since JavaScript itself is 17, so that would be the default maximum for JSON IMHO. However, different libraries for different languages may not have 17 for the native decimal types.
- JimDabell 10y ago> * The concatenation of valid JSON blobs is never valid JSON. You might want to check out JSON Lines: http://jsonlines.org/ http://jsonlines.org/
- adrianratnapala 10y agoIs there are formal defintion of the format anywhere?
- alexchamberlain 10y agoI would like timestamps introduced as a first class citizen, and can be done relatively cheaply. As the OP said, they are very common in protocols, and it would be nice to have 1 way of encoding them. Especially 1 that doesn't involve an arbitrary offset... The other suggestions are interesting, but rather distracting IMHO.
- pluma 10y agoIn my opinion there are five problems with JSON in practice: 1. Trailing commas should be allowed. This would fix the entire comma ordeal the author is complaining about without introducing awkward whitespace logic. 2. Date time values should be a distinct type using the format of JS's Date.prototype.toISOString method. Had this been in the language when JSON was originally defined I'm sure it'd already be in JSON. 3. There should be a way to represent Infinity (for IEEE 754 compatibility) and possibly NaN. 4. Comments would be nice because JSON is often used for configuration and documenting JSON snippets can get awkward without them. 5. There's no real way to represent binary data other than base64 encoded strings. It would be nice if there was at least some hex format (e.g. `"blob": <dead beef cafe babe>` with optional spaces for readability) but I can see why some people might be opposed to the idea of adding this to the language
- tech2 10y agoAlthough I'm personally not _as_ bothered by 5, the rest of these are spot-on. The other big annoyance for me is the inability to use anything other than string as an object key (numbers, for example, but others would be interesting/useful too I guess).
- tofflos 10y ago6. I'd love to see unquoted keys added to that list. Quotes could be used for cases when a key is not a valid identifier.
- grandinj 10y agoYes and double yes to comments! Otherwise it's useless as a configuration language
- dotandimet 10y ago... from the man who brought you null and string as valid JSON payloads (in the last RFC he authored). Thus making JSON less secure, trickier to parse and harder to reason about.
- wruza 10y agoJson is flawed in any way possible, imo. It was intended to be edited and read by human; it can not comments, trailing commas, non-quoted keys. It was planned for universal exchange; it doesn't contain dates, full-floats, byte arrays in readable form. It can't have backreferences for graph exchange or per-packet string interning. Even "obvious syntax" argument is wrong. "Key": value is not what comes to mind unless your parents spoke to you on js. Why it is still here: legacy that was easier to read-write than sgml-flavoured monster. Other arguments are nonsense.
- lukasm 10y agoWe are using https://hjson.org/ https://hjson.org/ to describe metadata of xml/json API and how to parse the result. It solves all the problems mentioned in the post.
- meirelles 10y agoI think JSON is great, because it's simple. Who really needs something more oriented for humans, take a look at HOCON. https://github.com/typesafehub/config https://github.com/typesafehub/config
- skywhopper 10y agoJSON is a beast to deal with for anyone who's manually editing it. All the comments here about special formatting strategies to avoid comma problems, or how to workaround the lack of a timestamp type just prove the point that JSON needs to fix these things.
- caseymarquis 10y agoToo much effort for too small a payoff. Would trailing commas and timestamps be nice. Yes. Would they be so nice that dealing with the json to json 1.1 transition would be worth it. Not really. On removal of commas I'd just disagree.
- spriggan3 10y agoOr you know, use something else like YAML.
- deleted 10y ago[deleted]