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.

Amazon open-sources Ion – a binary and text interchangable, typed JSON-superset

359 pointsby machinagodabout 9 years ago

28 comments

habermanabout 9 years ago
To think about the difference between serialization formats, here&#x27;s an analogy I hope will help.<p>Protocol Buffers (and I think Thrift, and maybe Avro) are sort of like C or C++: you declare your types ahead of time, and then you take some binary payload and &quot;cast&quot; it (parse it actually) into your predefined type. If those bytes weren&#x27;t actually serialized as that type, you&#x27;ll get garbage. On the plus side, the fact that you declared your types statically means that you get lots of useful compile-time checking and everything is really efficient. It&#x27;s also nice because you can use the schema file (ie. .proto files) to declare your schema formally and document everything.<p>JSON and Ion are more like a Python&#x2F;Javascript object&#x2F;dict. Objects are just attribute-value bags. If you say it has field fooBar at runtime, now it does! When you parse, you don&#x27;t have to know what message type you are expecting, because the key names are all encoded on the wire. On the downside, if you misspell a key name, nothing is going to warn you about it. And things aren&#x27;t quite as efficient because the general representation has to be a hash map where every value is dynamically typed. On the plus side, you never have to worry about losing your schema file.<p>I think this is a case where &quot;strongly typed&quot; isn&#x27;t the clearest way to think about it. It&#x27;s &quot;statically typed&quot; vs. &quot;dynamically typed&quot; that is the useful distinction.
评论 #11547072 未加载
评论 #11547089 未加载
评论 #11547666 未加载
评论 #11547049 未加载
leefabout 9 years ago
Finally! I&#x27;ve had to live the JSON nightmare since I left Amazon.<p>Some of the benefits over JSON:<p>* Real date type<p>* Real binary type - no need to base64 encode<p>* Real decimal type - invaluable when working with currency<p>* Annotations - You can tag an Ion field in a map with an annotation that says, e.g. its compression (&quot;csv&quot;, &quot;snappy&quot;) or its serialized type (&#x27;com.example.Foo&#x27;).<p>* Text and binary format<p>* Symbol tables - this is like automated jsonpack.<p>* It&#x27;s self-describing - meaning, unlike Avro, you don&#x27;t need the schema ahead of time to read or write the data.
评论 #11548223 未加载
评论 #11546771 未加载
评论 #11546940 未加载
评论 #11546791 未加载
评论 #11546947 未加载
评论 #11547300 未加载
kazinatorabout 9 years ago
I Consider this Harmful (TM) and will oppose the adoption in every organization where I have an opportunity to voice such. (In its present form, to be clear!)<p>There is no need to have a null which is fragmented into null.timestamp, null.string and whatever. It will complicate processing. Just because you know the type of some element is timestamp, you must worry whether or not it is null and what that means.<p>There should be just one null value, which is its own type. A given datum is either permitted to be null OR something else like a string. Or it isn&#x27;t; it is expected to be a string, which is distinct from the null value; no string is a null value.<p>It&#x27;s good to have a read notation for a timestamp, but it&#x27;s not an elementary type; a timestamp is clearly an aggregate and should be understood as corresponding to some structure type. A timestamp should be expressible using that structure, not only as a special token.<p>This monstrosity is not exhibiting good typing; it is not good static typing, and not good dynamic typing either. Under static typing we can have some &quot;maybe&quot; type instead of null.string: in some representations we definitely have a string. In some other places we have a &quot;maybe string&quot;, a derived type which gives us the possibility that a string is there, or isn&#x27;t. Under dynamic typing, we can superimpose objects of different type in the same places; we don&#x27;t need a null version of string since we can have &quot;the&quot; one and only null object there.<p>This looks like it was invented by people who live and breathe Java and do not know any other way of structuring data. Java uses statically typed references to dynamic objects, and each such reference type has a null in its domain so that &quot;object not there&quot; can be represented. But just because you&#x27;re working on a reference implementation in such a language doesn&#x27;t mean you cannot <i>transcend</i> the semantics of the implementation language. If you want to propose some broad interoperability standard, you practically <i>must</i>.
评论 #11547244 未加载
评论 #11549703 未加载
评论 #11547638 未加载
wycabout 9 years ago
This reminds me a lot of Avro:<p><a href="https:&#x2F;&#x2F;avro.apache.org&#x2F;docs&#x2F;current&#x2F;" rel="nofollow">https:&#x2F;&#x2F;avro.apache.org&#x2F;docs&#x2F;current&#x2F;</a><p>They both have self-describing schemas, support for binary values, JSON-interoperability, basic type systems (Ion seems to support a few more field types), field annotations, support for schema evolution, code generation not necessary, etc.<p>I think Avro has the additional advantages of being production-tested in many different companies, a fully-JSON schema, support for many languages, RPC baked into the spec, and solid performance numbers found across the web.<p>I can&#x27;t really see why I&#x27;d prefer Ion. It looks like an excellent piece of software with plenty of tests, no doubt, but I think I could do without &quot;clobs&quot;, &quot;sexprs&quot;, and &quot;symbols&quot; at this level of representation, and it might actually be better if I do. Am I missing something?
评论 #11546749 未加载
评论 #11546574 未加载
评论 #11547101 未加载
评论 #11546644 未加载
jonhohleabout 9 years ago
Big congrats to Todd, Almann, Chris, Henry, and everyone else who made this happen.<p>Several years ago, I wouldn&#x27;t have imagined this possible and I&#x27;m a little bummed that I left before it happened.<p>Like leef said above, I&#x27;m glad to have Ion as an option again.
评论 #11546994 未加载
评论 #11549914 未加载
评论 #11549500 未加载
desdivabout 9 years ago
Interestingly enough a JSON alternative named &quot;ION&quot; was just posted as a Show HN[0] about three months ago.<p>So now not only do we have the problem of redundant and mutually incompatible protocols (cue obligatory xkcd), but that we have <i>so many</i> such protocols that name collision is becoming an extra problem.<p>[0] <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=11027319" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=11027319</a>
评论 #11546642 未加载
drawkboxabout 9 years ago
Binary values can be stored as base64 in regular old JSON as well. Yes that is bigger but same as email&#x2F;MIME binary chunks are converted to base64. Email messages and attachments are handled this way, we do this everyday. Base64 does bloat by 40%ish, so the larger content could be compressed&#x2F;decompressed prior to base64 encoding it and vice versa or even encrypted&#x2F;decrypted on either end in software&#x2F;app layer.<p>No need for a new protocol when doing it that way for basic things, if you need more binary (busy messaging&#x2F;real-time) there are plenty of alternatives to JSON.<p>I love the simplicity of JSON, so do others and it is successful so many try to attach on to that success. The success part was that it was so damn simple though, most attachments just complicate and add verbosity, echoes back to XML and SOAP wars which spawned the plain and simple JSON. Adding complexity is easy and anyone can do it, good engineers take complexity and make it simple, that is damn difficult.
评论 #11549969 未加载
deathanatosabout 9 years ago
I can&#x27;t decide if &quot;JSON-superset&quot; is technically accurate or not.<p>JSON&#x27;s string literals come from JavaScript, and JavaScript only sortof has a Unicode string type. So the \u escape in both languages encodes a UTF-16 code <i>unit</i>, not a code <i>point</i>. That means in JSON, the single code point U+1f4a9 &quot;Pile of Poo&quot; is encoded thusly:<p><pre><code> &quot;\ud83d\udca9&quot; </code></pre> JSON specifically says this, too,<p><pre><code> Any character may be escaped. If the character is in the Basic Multilingual Plane (U+0000 through U+FFFF), then it may be represented as a six-character sequence: a reverse solidus, followed by the lowercase letter u, followed by four hexadecimal digits that encode the character&#x27;s code point. The hexadecimal letters A though F can be upper or lowercase. So, for example, a string containing only a single reverse solidus character may be represented as &quot;\u005C&quot;. [… snip …] To escape an extended character that is not in the Basic Multilingual Plane, the character is represented as a twelve-character sequence, encoding the UTF-16 surrogate pair. So, for example, a string containing only the G clef character (U+1D11E) may be represented as &quot;\uD834\uDD1E&quot;. </code></pre> Now, Ion&#x27;s spec says only:<p><pre><code> U+HHHH \uHHHH 4-digit hexadecimal Unicode code point </code></pre> But if we take it to mean code <i>point</i>, then if the value is a surrogate… what should happen?<p>Looking at the code, it <i>looks</i> like the above JSON will parse:<p><pre><code> 1. Main parsing of \u here: https:&#x2F;&#x2F;github.com&#x2F;amznlabs&#x2F;ion-java&#x2F;blob&#x2F;1ca3cbe249848517fc6d91394bb493383d69eb61&#x2F;src&#x2F;software&#x2F;amazon&#x2F;ion&#x2F;impl&#x2F;IonReaderTextRawTokensX.java#L2429-L2434 2. which is called from here, and just appended to a StringBuilder: https:&#x2F;&#x2F;github.com&#x2F;amznlabs&#x2F;ion-java&#x2F;blob&#x2F;1ca3cbe249848517fc6d91394bb493383d69eb61&#x2F;src&#x2F;software&#x2F;amazon&#x2F;ion&#x2F;impl&#x2F;IonReaderTextRawTokensX.java#L1975 </code></pre> My Java isn&#x27;t that great though, so I&#x27;m speculating. But I&#x27;m not sure what <i>should</i> happen.<p>This is just one of those things that the first time I saw it in JSON&#x2F;JS… a part of my brain melted. This is all a technicality, of course, and most JSON values should work just fine.
评论 #11547621 未加载
escherizeabout 9 years ago
Is there a source for benchmarks&#x2F;reviews for the various ways to represent data? As far as I see it, there are a lot of them that I&#x27;d like to hear pros&#x2F;cons for: json, edn + transit (my fave), yaml, google protobufs, thrift (?), as well as Ion.<p>And where does Ion fit here?
评论 #11546785 未加载
评论 #11546711 未加载
评论 #11547653 未加载
eyanabout 9 years ago
Surprised nobody mentioned CBOR (<a href="http:&#x2F;&#x2F;cbor.io" rel="nofollow">http:&#x2F;&#x2F;cbor.io</a>) yet. Aka RFC 7049 (<a href="http:&#x2F;&#x2F;tools.ietf.org&#x2F;html&#x2F;rfc7049" rel="nofollow">http:&#x2F;&#x2F;tools.ietf.org&#x2F;html&#x2F;rfc7049</a>).
评论 #11547149 未加载
vparikhabout 9 years ago
Wasn&#x27;t this solved already by the BSON specification - <a href="http:&#x2F;&#x2F;bsonspec.org" rel="nofollow">http:&#x2F;&#x2F;bsonspec.org</a> ? Sure this allows you a definition of types, but this could easily be done using standard JSON meta data for each field. I find BSON simpler and more elegant.
评论 #11546945 未加载
Ericson2314about 9 years ago
&gt; Decimal maintains precision: -0. != -0.0<p>What? This means their &quot;arbitrary-precision decimals&quot; are actually isomorphic to (Rational x Natural).
评论 #11546734 未加载
评论 #11547002 未加载
saosebastiaoabout 9 years ago
Do any of the popular message serialization formats have first class support for algebraic data types? It seems like every one I&#x27;ve researched has to be hacked in some way to provide for sum types.
评论 #11546914 未加载
评论 #11547311 未加载
kevinSuttleabout 9 years ago
Would like to see a comparison to EDN. <a href="https:&#x2F;&#x2F;github.com&#x2F;edn-format&#x2F;edn" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;edn-format&#x2F;edn</a>
akavelabout 9 years ago
Can anyone share links to some examples, showcasing the differentiating features vs. json? I couldn&#x27;t easily find any via the main link
userbinatorabout 9 years ago
Almost every time I see yet another structured data format I&#x27;m surprised at the number of people who haven&#x27;t ever heard of ASN.1, despite it forming the basis of <i>many</i> protocols in widespread use.
评论 #11547065 未加载
评论 #11557241 未加载
评论 #11550656 未加载
cm3about 9 years ago
A question for frontend devs: Will H2 being binary on the wire inspire more use of binary data representations as well, with conversion to JSON only on the client? Passing around JSON or XML across a big SOA (or micro-services) architecture is a waste of cycles and doesn&#x27;t have types attached for reliability and security.
评论 #11546834 未加载
blake8086about 9 years ago
How does Ion help with schema evolution? I see it mentioned, but not described.
评论 #11547010 未加载
tn13about 9 years ago
This appears to be something in between of JSON and Protocol buffers. I wonder under what conditions Ion makes more sense than either of the JSON&#x2F;PBuff.
评论 #11546848 未加载
评论 #11546770 未加载
viraptorabout 9 years ago
So far, most of the interesting bits I see in Ion are covered in YAML (which is also JSON-superset). Most of the rest are extra types, which YAML allows you to implement. The only really missing bit is the binary encoding... but that seems unrelated to the text format itself.<p>This really looks like a NIH specification.
评论 #11547186 未加载
coldcodeabout 9 years ago
Is there any other implementation besides Java? I would be using it from iOS.
voltagex_about 9 years ago
Open question to anyone reading this: Would you use Ion if you were designing a new house-wide message queue? (e.g. broadcast messages to &#x2F;Home&#x2F;Lounge&#x2F;Lights&#x2F; to turn on&#x2F;off)
评论 #11547323 未加载
评论 #11546867 未加载
评论 #11546884 未加载
kilinkabout 9 years ago
Things I dislike about Ion, having used it while at Amazon:<p>- IonValues are mutable by default. I saw bugs where cached IonValues were accidentally changed, which is easy to do: IonSequence.extract clears the sequence [1], adding an IonValue to a container mutates the value (!) [2], etc.<p>- IonValues are not thread-safe [3]. You can call makeReadOnly() to make them immutable, but then you&#x27;ll be calling clone since doing anything useful (like adding it to a list) will need to mutate the value. While it says IonValues are not even thread-safe for reading, I believe this is not strictly true. There was an internal implementation that would lazily materialize values on read, but it doesn&#x27;t look like it&#x27;s included in the open source version.<p>- IonStruct can have multiple fields with the same name, which means it can&#x27;t implement Map. I&#x27;ve never seen anyone use this (mis)feature in practice, and I don&#x27;t know where it would be useful.<p>- Since IonStruct can&#x27;t implement Map, you don&#x27;t get the Java 8 default methods like forEach, getOrDefault, etc.<p>- IonStruct doesn&#x27;t implement keySet, values, spliterator, or stream, and thus doesn&#x27;t play well with the Java 8 Stream API.<p>- Calling get(fieldName) on an IonStruct returns null if the field isn&#x27;t present. But the value might also be there and be null, so you end up having to do a null check AND call isNullValue(). I&#x27;m not convinced it&#x27;s a worthwhile distinction, and would have preferred a single way of doing it. You can already call containsKey to check for the presence of a field.<p>- In practice most code that dealt with Ion was nearly as tedious and verbose as pulling values out of an old-school JSONObject. Every project seemed to have a slightly different IonUtils class for doing mundane things like pulling values out of structs, doing all the null checks, casting, etc. There was some kind of adapter for Jackson that would allow you to deserialize to a POJO, but it didn&#x27;t seem like it was widely used.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;amznlabs&#x2F;ion-java&#x2F;blob&#x2F;master&#x2F;src&#x2F;software&#x2F;amazon&#x2F;ion&#x2F;IonSequence.java#L457" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;amznlabs&#x2F;ion-java&#x2F;blob&#x2F;master&#x2F;src&#x2F;softwar...</a><p>[2] <a href="https:&#x2F;&#x2F;github.com&#x2F;amznlabs&#x2F;ion-java&#x2F;blob&#x2F;master&#x2F;src&#x2F;software&#x2F;amazon&#x2F;ion&#x2F;IonValue.java#L103-L112" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;amznlabs&#x2F;ion-java&#x2F;blob&#x2F;master&#x2F;src&#x2F;softwar...</a><p>[3] <a href="https:&#x2F;&#x2F;github.com&#x2F;amznlabs&#x2F;ion-java&#x2F;blob&#x2F;master&#x2F;src&#x2F;software&#x2F;amazon&#x2F;ion&#x2F;IonValue.java#L119-L140" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;amznlabs&#x2F;ion-java&#x2F;blob&#x2F;master&#x2F;src&#x2F;softwar...</a>
评论 #11568969 未加载
intrasightabout 9 years ago
I use this <a href="http:&#x2F;&#x2F;dataprotocols.org&#x2F;tabular-data-package&#x2F;" rel="nofollow">http:&#x2F;&#x2F;dataprotocols.org&#x2F;tabular-data-package&#x2F;</a>
inceptedabout 9 years ago
&gt; &lt;groupId&gt;software.amazon.ion&lt;&#x2F;groupId&gt;<p>Why not &quot;com.amazon.ion&quot;, like thousands of other existing packages?
评论 #11547894 未加载
评论 #11559034 未加载
评论 #11559035 未加载
stolsvikabout 9 years ago
Are there any object marshalling&#x2F;serialization solution for Ion? (Like GSON, Jackson)
评论 #11551336 未加载
评论 #11559232 未加载
voltagex_about 9 years ago
I wonder how difficult this would be to port to C#?
breatheoftenabout 9 years ago
Why this instead of clojures &quot;transit&quot;?