9 <meta property=
"og:title" content=
"ion/: Tutorial/:2. What is ion">
10 <meta name=
"viewport" content=
"width=1200, initial-scale=0.5">
11 <base href=
"/ext-ion/v0.1/">
12 <meta http-equiv=
"Content-Location" content=
"/ext-ion/v0.1/ion/: Tutorial/:2. What is ion">
13 <link rel=
"stylesheet" href=
"index.css">
15 <link rel=
"shortcut icon" href=
"/ext-ion/v0.1/favicon.ico">
23 <a href=
"https://github.com/awesomized/ext-ion/edit/master/ion.stub.php">Edit
</a>
28 <li>↰ <a href=
"./">Home
</a>
33 ↑ <a href=
"./ion">
39 ↑ <a href=
"./ion/: Tutorial">
45 ↻ <strong><a href=
"./ion/: Tutorial/:2. What is ion">★
2. What is ion
</a></strong>
51 <li>↲ <a href=
"./ion/: Tutorial/:2. What is ion?">★
2. What is ion?
</a></li>
61 <meta charset=
"utf-8"><h2 id=
"What.Is.Ion.">What Is Ion?
<a class=
"permalink" href=
"ion/:%20Tutorial/:2.%20What%20is%20ion#What.Is.Ion.">#
</a>
62 </h2><p>Quoting the
<a href=
"https://amzn.github.io/ion-docs/">official Ion documentation
</a>:
</p><blockquote>
63 <p><strong>Amazon Ion
</strong> is a
<a href=
"https://amzn.github.io/ion-docs/guides/why.html#rich-type-system">richly-typed
</a>,
<a href=
"https://amzn.github.io/ion-docs/guides/why.html#self-describing">self-describing
</a>, hierarchical data serialization format offering
<a href=
"https://amzn.github.io/ion-docs/guides/why.html#dual-format-interoperability">interchangeable binary and text
</a> representations. The
<a href=
"https://amzn.github.io/ion-docs/docs/spec.html">text format
</a> (a superset of
<a href=
"http://json.org/">JSON
</a>) is easy to read and author, supporting rapid prototyping. The
<a href=
"https://amzn.github.io/ion-docs/docs/binary.html">binary representation
</a> is
<a href=
"https://amzn.github.io/ion-docs/guides/why.html#read-optimized-binary-format">efficient to store, transmit, and skip-scan parse
</a>. The rich type system provides unambiguous semantics for
<code><a href=
"https://php.net/manual/en/language.types.integer">long
</a></code>-term preservation of data which can survive multiple generations of software evolution.
</p>
64 <p>Ion was built to address rapid development, decoupling, and efficiency challenges faced every day while engineering large-scale, service-oriented architectures. It has been addressing these challenges within Amazon for nearly a decade, and we believe others will benefit as well.
</p>
65 </blockquote><h3 id=
"Simple.serialization">Simple serialization
<a class=
"permalink" href=
"ion/:%20Tutorial/:2.%20What%20is%20ion#Simple.serialization">#
</a>
66 </h3><pre><code><span style=
"color: inherit" class=
"html">
67 <span style=
"color: inherit" class=
"default"><?php
<br></span><span style=
"color: inherit" class=
"keyword">echo
</span><span style=
"color: inherit" class=
"default">ion\serialize
</span><span style=
"color: inherit" class=
"keyword">([
<br> </span><span style=
"color: inherit" class=
"string">"key" </span><span style=
"color: inherit" class=
"keyword">=
> </span><span style=
"color: inherit" class=
"string">"value"</span><span style=
"color: inherit" class=
"keyword">,
<br> </span><span style=
"color: inherit" class=
"string">"more" </span><span style=
"color: inherit" class=
"keyword">=
> [
<br> </span><span style=
"color: inherit" class=
"string">"data" </span><span style=
"color: inherit" class=
"keyword">=
> </span><span style=
"color: inherit" class=
"default">123<br> </span><span style=
"color: inherit" class=
"keyword">]
<br>]);
<br></span><span style=
"color: inherit" class=
"default">?
><br></span>
69 </code></pre><h4 id=
"Output:">Output:
<a class=
"permalink" href=
"ion/:%20Tutorial/:2.%20What%20is%20ion#Output:">#
</a>
70 </h4><pre><code><span style=
"color: inherit" class=
"html">
71 {key:
"value",more:{data:
123}}
<br></span>
72 </code></pre><p>If you now think that this looks a lot like JSON, you're probably right, because Ion is a superset of JSON:
</p><pre><code><span style=
"color: inherit" class=
"html">
73 <span style=
"color: inherit" class=
"default"><?php
<br></span><span style=
"color: inherit" class=
"keyword">echo
</span><span style=
"color: inherit" class=
"default">json_encode
</span><span style=
"color: inherit" class=
"keyword">([
<br> </span><span style=
"color: inherit" class=
"string">"key" </span><span style=
"color: inherit" class=
"keyword">=
> </span><span style=
"color: inherit" class=
"string">"value"</span><span style=
"color: inherit" class=
"keyword">,
<br> </span><span style=
"color: inherit" class=
"string">"more" </span><span style=
"color: inherit" class=
"keyword">=
> [
<br> </span><span style=
"color: inherit" class=
"string">"data" </span><span style=
"color: inherit" class=
"keyword">=
> </span><span style=
"color: inherit" class=
"default">123<br> </span><span style=
"color: inherit" class=
"keyword">]
<br>]);
<br></span><span style=
"color: inherit" class=
"default">?
><br></span>
75 </code></pre><h4 id=
"Output:">Output:
<a class=
"permalink" href=
"ion/:%20Tutorial/:2.%20What%20is%20ion#Output:">#
</a>
76 </h4><pre><code><span style=
"color: inherit" class=
"html">
77 {
"key":
"value",
"more":{
"data":
123}}
<br></span>
78 </code></pre><p>So, all valid JSON is also valid Ion. Please refer to the
<a href=
"https://amzn.github.io/ion-docs/docs/spec.html">official spec
</a> to learn more about this topic.
</p><h3 id=
"Simple.unserialization">Simple unserialization
<a class=
"permalink" href=
"ion/:%20Tutorial/:2.%20What%20is%20ion#Simple.unserialization">#
</a>
79 </h3><pre><code><span style=
"color: inherit" class=
"html">
80 <span style=
"color: inherit" class=
"default"><?=
<br>var_representation
</span><span style=
"color: inherit" class=
"keyword">(
<br> </span><span style=
"color: inherit" class=
"default">ion\unserialize
</span><span style=
"color: inherit" class=
"keyword">(
</span><span style=
"color: inherit" class=
"string">'{key:
"value",more:{data:
123}}'
</span><span style=
"color: inherit" class=
"keyword">)
<br>);
<br></span><span style=
"color: inherit" class=
"default">?
><br></span>
82 </code></pre><h4 id=
"Output:">Output:
<a class=
"permalink" href=
"ion/:%20Tutorial/:2.%20What%20is%20ion#Output:">#
</a>
83 </h4><pre><code><span style=
"color: inherit" class=
"html">
84 [
<br> 'key' =
> 'value',
<br> 'more' =
> [
<br> 'data' =
> 123,
<br> ],
<br>]
<br></span>
85 </code></pre><p>If you try the same with the JSON equivalent, you'll see that it's basically valid Ion, too:
</p><pre><code><span style=
"color: inherit" class=
"html">
86 <span style=
"color: inherit" class=
"default"><?=
<br>var_representation
</span><span style=
"color: inherit" class=
"keyword">(
<br> </span><span style=
"color: inherit" class=
"default">ion\unserialize
</span><span style=
"color: inherit" class=
"keyword">(
</span><span style=
"color: inherit" class=
"string">'{
"key":
"value",
"more":{
"data":
123}}'
</span><span style=
"color: inherit" class=
"keyword">)
<br>);
<br></span><span style=
"color: inherit" class=
"default">?
><br></span>
88 </code></pre><h4 id=
"Output:">Output:
<a class=
"permalink" href=
"ion/:%20Tutorial/:2.%20What%20is%20ion#Output:">#
</a>
89 </h4><pre><code><span style=
"color: inherit" class=
"html">
90 [
<br> 'key' =
> 'value',
<br> 'more' =
> [
<br> 'data' =
> 123,
<br> ],
<br>]
<br></span>
91 </code></pre><h3><a class=
"permalink" href=
"ion/:%20Tutorial/:2.%20What%20is%20ion#">#
</a></h3>
92 <div class=
"comments">
93 <style>.giscus-frame {min-height:
16em;}
</style>
95 function giscus_load(button) {
96 let script = document.createElement(
"script");
97 script.setAttribute(
"data-repo", 'awesomized/ext-ion');
98 script.setAttribute(
"data-category", 'Comments on Docs');
99 script.setAttribute(
"data-repo-id", 'R_kgDOGfXEXw');
100 script.setAttribute(
"data-category-id", 'DIC_kwDOGfXEX84CBHuf');
101 script.setAttribute(
"data-mapping", 'og:title');
102 script.setAttribute(
"data-input-position", 'bottom');
103 script.setAttribute(
"data-reactions-enabled", false);
104 script.setAttribute(
"data-theme", 'light');
105 script.setAttribute(
"data-lang", 'en');
107 script.src =
"//giscus.app/client.js";
108 button.parentNode.replaceChild(script, button);
111 <button class=
"activator" onclick=
"giscus_load(this)">Show Comments from Github Discussions
</button>
118 <li><a href=
"https://github.com/m6w6/mdref">mdref-v3.0
120 <li><a href=
"LICENSE">© 2013-
2022 All rights reserved.
</a></li>
127 <script src=
"index.js" defer
></script>