docs: tutorial
[awesomized/ext-ion] / docs / v0.1 / ion / : Tutorial / :2. What is ion?.html
1 <!doctype html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>
62. What is ion -
7 mdref
8 </title>
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">
14
15 <link rel="shortcut icon" href="/ext-ion/v0.1/favicon.ico">
16 </head>
17 <body>
18 <div class="page">
19
20 <div class="sidebar">
21
22 <div class="edit">
23 <a href="https://github.com/awesomized/ext-ion/edit/master/ion.stub.php">Edit</a>
24 </div>
25
26
27 <ul>
28 <li>&lsh; <a href="./">Home</a>
29
30 <ul>
31 <li>
32
33 &uarr; <a href="./ion">
34 ion
35 </a>
36 <ul>
37 <li>
38
39 &uarr; <a href="./ion/: Tutorial">
40 ★ Tutorial
41 </a>
42 <ul>
43 <li>
44
45 &circlearrowright; <strong><a href="./ion/: Tutorial/:2. What is ion">2. What is ion</a></strong>
46
47
48
49 </ul>
50
51 <li>&ldsh; <a href="./ion/: Tutorial/:2. What is ion?">2. What is ion?</a></li>
52
53 </ul>
54
55 </li>
56 </ul>
57
58 </li>
59 </ul>
60 </div>
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">&lt;?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">=&gt; </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">=&gt; [<br>    </span><span style="color: inherit" class="string">"data" </span><span style="color: inherit" class="keyword">=&gt; </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">?&gt;<br></span>
68 </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">&lt;?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">=&gt; </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">=&gt; [<br>    </span><span style="color: inherit" class="string">"data" </span><span style="color: inherit" class="keyword">=&gt; </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">?&gt;<br></span>
74 </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">&lt;?=<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">?&gt;<br></span>
81 </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' =&gt; 'value',<br>  'more' =&gt; [<br>    'data' =&gt; 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">&lt;?=<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">?&gt;<br></span>
87 </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' =&gt; 'value',<br>  'more' =&gt; [<br>    'data' =&gt; 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>
94 <script>
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');
106
107 script.src = "//giscus.app/client.js";
108 button.parentNode.replaceChild(script, button);
109 }
110 </script>
111 <button class="activator" onclick="giscus_load(this)">Show Comments from Github Discussions</button>
112
113 </div>
114
115 <footer>
116
117 <ul>
118 <li><a href="https://github.com/m6w6/mdref">mdref-v3.0
119 </a></li>
120 <li><a href="LICENSE">&copy; 2013-2022 All rights reserved.</a></li>
121 <li>
122 </li>
123 </ul>
124
125 </footer>
126
127 <script src="index.js" defer></script>
128
129 </div>
130 </body>
131 </html>