6 ms·
Show HN: Weird JSON superset with BigInt, Infinity, TypedArray etc
- jauco 6y agoThis sucks. Real JSON is waay better than OP. Or at least use Protobuf, it's popular and created by Google, or bson. Don't use this, it's clearly a security nightmare.
- yamrzou 6y agoHmm, interesting idea. Have you ever heard of Base64? Just curious why you chose to name it 46? And why JSON? There's specific definitions of 46, and JSON, and they don't say anything about this. Did I miss something in the JSON spec?
- w-m 6y agoI mean it's clearly a joke, but... Why not? A new standard, great idea! Just a reminder to everyone, try this out in production!
- bonkabonka 6y agoIf you're going to enhance JSON, you might consider how you could support comments in unencoded files at-rest on disk.
- taywrobel 6y agoLike JSON5?
- dmitriid 6y agoAnd still no specification for `datetime`. I can't for the life of me understand why protocol specs omit this.
- ben509 6y agoBecause people think they want "time since epoch" but they really want ISO8601 because they'd like it to be readable, and oh, btw, durations would be nice, too. That spec is quite large, and everyone wants different parts of it. And different languages have different and somewhat incompatible support for datetimes. And, worse, people want different behavior for invalid datetimes. So your parser either balloons in size and requirements and its test-suite or restricts it to a handful of cases, at which point for most users, your datetime type is useless. This is why if you have a protocol like JSON that allows you to construct arbitrary types or simply parse strings, you let users figure out how to handle it.
- stickfigure 6y agoNah. The notion of a "time since arbitrary epoch" is pretty universal, even though it may have a variety of representations. Just pick one, it really doesn't matter which. Actually JavaScript already did pick a representation - milliseconds since 1970. It would be easy and unambiguous to add { "foo": T1606410158672 } to the grammar.
- ben509 6y agoAnd I think nobody does that in a protocol because you're adding extra complexity to get you little more than transmitting a number.
- dmitriid 6y agoYou get significantly more than transmitting a number. - You get automatic conversion to/from a known datatype, Timestamp, not to an arbitrary number - You get automatic checks on the validity of this datatype - You can specify exact precision of this datatype (for example, you may want to represent nanoseconds, not milliseconds, since epoch)
- dmitriid 6y ago> And different languages have different and somewhat incompatible support for datetimes. The support for datetimes is irrelevant if the protocol spec specifies how to serialize a date. Converters for languages will appear or already exist. Datetimes is one of the most common data types and yes, everyone ends up "constructing arbitrary types or simply parsing strings and letting users guess how to handle stuff". Remember .NET's handling of datetime? [1] ISO 8601 was published in 1988. You'd think that protocols designed in the 21st century would at least know about it. You don't have to require all of it. A sensible expectation of date and datetime would suffice the vast majority of use cases. [1] https://www.hanselman.com/blog/on-the-nightmare-that-is-json-dates-plus-jsonnet-and-aspnet-web-api https://www.hanselman.com/blog/on-the-nightmare-that-is-json...
- ben509 6y ago
- cookiengineer 6y agoI'm not sure whether this is a joke? Is it just to mess with devs? Is this what video streaming websites' "DMCA crypto" websockets will use in future? Is this like jsfuck for JSON? Why use a static alphabet and not a dynamic one, e.g. with a magic header hidden somewhere that automatically changes the alphabet once parsed for the following content, including other magic alphabet headers? /s edit: Can my comment make it into testimonials, too, plz?
- recov 6y agoDamn. This is clearly just a fun exercise by OP, and most people here are judging it as if this is a serious project they want people to use in production or something.
- mauflows 6y agoJust commenting to get featured in the README
- emptyparadise 6y agoI'll take it over YAML.
- ghayes 6y agoI know these are all jokes, but this doesn't actually assume the role of YAML or JSON, which are focused around human-readable, human-editable formats. This would be way cooler, IMO, if it didn't encode into base36 since there are plenty of good tools for binary-serialized formats.
- bArray 6y agoI'm of the opinion that any types other than strings in JSON is a mistake - any parsing assumptions will _never_ be future sufficient. It should be the user of the library's responsibility to implement their own string->type conversions.
- skrebbel 6y agoEven null and booleans?
- shawnz 6y agoI think null at least is a great example of their point since many applications might not want a "null" type. Although I am not sure I would go as far as to drop booleans. As for numeric types, that's a complicated issue, I think they should be supported for pragmatic reasons even though it's impossible to come up with a numeric type that satisfies everyone.
- bArray 6y agoI think booleans might even be the most problematic, as it's _really_ implementation specific. In C for example you might expect 1 == TRUE, but in other languages this is not the case. The real problems come in when you handle unexpected cases - and there's no real answer as to whether you return true, false or an error. Personally I think the responsibility should be thrown back at the coder. E.g. I will sometimes do: if(!(jobj.get("key", "true").contains("f")))fun(); Where "true" is considered safe and default. Generally you need to make some effort to switch it off by making sure an "f" exists somewhere, but either case is fine. Imagine for example that the value "true" turns on something potentially dangerous, you might want to guard against accidentally switching it on with: if(jobj.get("key", "false").equals("true"))fun(); So you for sure have to make sure the string is "true" to switch it on, nothing else.
- bArray 6y ago> Even null and booleans? I would say so yes. Pick null for example, depending on your language of choice, you might choose to utilize: "null", "NULL", "", "undefined", "\0", etc. The same with booleans, are we speaking "true", "True", "TRUE", "1", "0xFFFFFFFF", or anything that isn't a false is true, etc. Really how you want to handle these situations is entirely up to you. Personally I prefer some functions like: string s = jobj.get(key, default) The default value being used if a valid string could not be found. Your default could of course be null or equivalent (handle the error), or it could be some known safe value (the show must go on).
- francisduvivier 6y agoHaters gonna hate, go for it!
- shawnz 6y agoI realize this is not entirely serious, but if it were to be improved, I would like to see the ASCII safety features moved into a separate product from the extended JSON type features. It would be easier to take some "extended" JSON encoded in UTF-8 and just base-64 it if I needed the ASCII safety.
- montroser 6y agoSorry, but this is awesome. It's not really what you probably want in most situations. But sometimes you have constraints that come with legacy systems. Adding another layer of Base64 encoding comes with its own set of compatibility quirks, impedes introspection and debugability, and still doesn't help with BigInt's and the like. For systems where you have modern stacks and control all the moving parts, something like Cap'n Proto will likely make everyone happier in the end. But you don't always have that luxury, and this project is very cool in its own right...
- ronsor 6y agoI added this to my project, and it was at least 250% faster than standard JSON functions somehow. 10/10 would recommend.
- cghendrix 6y agoI don’t see the comment from HN here. Lies
- deleted 6y ago[deleted]
- ellis0n 6y agoAmazing job! JSON can be improved like HTML 1.0
- deleted 6y ago[deleted]