index.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <!doctype html>
  2. <html lang="en-nz">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <title>Invercargill-Json — Astrologue Developer</title>
  7. <meta name="description" content="JSON support for Invercargill: documents become Enumerable collections that query and transform like any other sequence — JsonElement, JsonArray, JsonObject and JSON Lines streams. Free software, LGPL-3.0-or-later.">
  8. <meta name="color-scheme" content="light dark">
  9. <meta name="theme-color" content="#f2ebda" media="(prefers-color-scheme: light)">
  10. <meta name="theme-color" content="#0a0a12" media="(prefers-color-scheme: dark)">
  11. <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Ccircle cx='32' cy='32' r='27' fill='none' stroke='%23a8801f' stroke-width='4'/%3E%3Cpath d='M32 8l6 18 18 6-18 6-6 18-6-18-18-6 18-6z' fill='%23a8801f'/%3E%3Ccircle cx='32' cy='32' r='4' fill='%23003078'/%3E%3C/svg%3E">
  12. <meta property="og:title" content="Invercargill-Json — Astrologue Developer">
  13. <meta property="og:description" content="JSON support for Invercargill: documents become Enumerable collections that query and transform like any other sequence.">
  14. <meta property="og:type" content="website">
  15. <link rel="stylesheet" href="../../assets/css/style.css">
  16. </head>
  17. <body>
  18. <a class="skip-link" href="#main">Skip to content</a>
  19. <header class="masthead">
  20. <div class="container masthead__inner">
  21. <a class="brand" href="../../">
  22. <img class="brand__logo brand__logo--light" src="../../assets/img/astrologue-light.png" width="392" height="89" alt="Astrologue">
  23. <img class="brand__logo brand__logo--dark" src="../../assets/img/astrologue-dark.png" width="392" height="89" alt="Astrologue">
  24. </a>
  25. <nav class="site-nav" aria-label="Primary">
  26. <ul class="site-nav__list">
  27. <li><a href="../../">Home</a></li>
  28. <li><a href="../../#news">News</a></li>
  29. <li><a href="../../#download">Download</a></li>
  30. <li><a href="../" aria-current="page">Developer</a></li>
  31. <li><a class="nav-cta" href="../../#download">Get Astrologue</a></li>
  32. </ul>
  33. </nav>
  34. </div>
  35. </header>
  36. <main id="main">
  37. <nav class="breadcrumb" aria-label="Breadcrumb">
  38. <div class="container">
  39. <ol>
  40. <li><a href="../../">Astrologue</a></li>
  41. <li><a href="../">Developer</a></li>
  42. <li aria-current="page">Invercargill-Json</li>
  43. </ol>
  44. </div>
  45. </nav>
  46. <section class="docs-header">
  47. <div class="container">
  48. <p class="kicker"><span>Foundation · Documents as sequences</span></p>
  49. <h1>Invercargill-Json</h1>
  50. <p class="lede">JSON support for Invercargill: a document becomes an Enumerable collection that queries and transforms like any other sequence. Json-glib does the parsing; this library gives its nodes the interface the rest of the stack speaks.</p>
  51. <dl class="docs-facts">
  52. <div><dt>Version</dt> <dd><code>0.1</code></dd></div>
  53. <div><dt>Licence</dt> <dd>LGPL-3.0-or-later</dd></div>
  54. <div><dt>Package</dt> <dd><code>usm&nbsp;install&nbsp;invercargill-json</code></dd></div>
  55. <div><dt>Language</dt> <dd>Vala</dd></div>
  56. </dl>
  57. </div>
  58. </section>
  59. <section class="band band--plain" id="docs">
  60. <div class="container docs-layout">
  61. <nav class="docs-toc" aria-label="On this page">
  62. <h2>On this page</h2>
  63. <ul>
  64. <li><a href="#overview">Overview</a></li>
  65. <li><a href="#features">Features</a></li>
  66. <li><a href="#installation">Installation</a></li>
  67. <li><a href="#usage">Usage &amp; documentation</a></li>
  68. <li><a href="#package">Package &amp; source</a></li>
  69. </ul>
  70. </nav>
  71. <div class="docs-prose">
  72. <header class="section-head" id="overview">
  73. <p class="kicker"><span>Overview</span></p>
  74. <h2>A compact companion</h2>
  75. </header>
  76. <p>Invercargill-Json provides JSON functionality to Invercargill — that single sentence is the library's whole README, and it is an honest measure of the project's scope. This is a compact companion library, not an exercise in surface area: five small source files that wrap json-glib's nodes in Invercargill types so a JSON document answers the same queries as a database result or a settings file.</p>
  77. <p>Its worth shows up in the stack above it: Statum's signed state slots serialise through it, and the fixes it carries — integers serialising as JSON numbers rather than boxed strings, large <code>int64</code> values round-tripping without precision loss — were found in exactly that downstream path.</p>
  78. <header class="section-head" id="features">
  79. <p class="kicker"><span>Features</span></p>
  80. <h2>What it hands you</h2>
  81. </header>
  82. <ul class="docs-features">
  83. <li><strong>JsonElement.</strong> One element type for any node, parsed from a string, a file or a stream — including an async stream variant.</li>
  84. <li><strong>Typed access.</strong> <code>assert_as&lt;T&gt;</code> and <code>try_get_as&lt;T&gt;</code> turn nodes into the Vala types you actually wanted.</li>
  85. <li><strong>Queryable documents.</strong> Arrays and objects are Enumerable: filter, project, aggregate and order a document with the same calls as any sequence.</li>
  86. <li><strong>JsonElements promotions.</strong> <code>as_strings()</code>, <code>as_integers()</code>, <code>as_doubles()</code>, <code>as_bools()</code>, <code>as_objects()</code>, <code>as_property_groups()</code> project a node sequence straight onto typed values.</li>
  87. <li><strong>JSON Lines.</strong> Stream <code>.jsonl</code> in and out through <code>JsonlInputStream</code> and <code>JsonlOutputStream</code>, one element at a time.</li>
  88. <li><strong>Objects as Properties.</strong> A <code>JsonObject</code> is an associative Enumerable of key-value pairs, so property mapping works on documents too.</li>
  89. </ul>
  90. <header class="section-head" id="installation">
  91. <p class="kicker"><span>Installation</span></p>
  92. <h2>Getting the library</h2>
  93. </header>
  94. <p>Install the foundation first, then this companion:</p>
  95. <figure class="code-plate">
  96. <pre><code>usm install invercargill
  97. usm install invercargill-json</code></pre>
  98. <figcaption>USM resolves the <code>invercargill-1</code> and <code>json-glib</code> dependencies itself.</figcaption>
  99. </figure>
  100. <p>From source:</p>
  101. <figure class="code-plate">
  102. <pre><code>git clone &lt;the Invercargill-Json repository&gt;
  103. cd Invercargill-Json
  104. meson setup build
  105. ninja -C build
  106. ninja -C build install</code></pre>
  107. <figcaption>Meson and ninja are the only build tools needed.</figcaption>
  108. </figure>
  109. <figure class="code-plate">
  110. <pre><code>valac --pkg invercargill-json my-program.vala</code></pre>
  111. <figcaption>The binding pulls in its <code>.deps</code> chain automatically.</figcaption>
  112. </figure>
  113. <header class="section-head" id="usage">
  114. <p class="kicker"><span>Usage &amp; documentation</span></p>
  115. <h2>Reading documents as sequences</h2>
  116. </header>
  117. <p>Parse, assert the shape, project to types — the library's own tests read like documentation:</p>
  118. <figure class="code-plate">
  119. <pre><code>using Invercargill;
  120. using InvercargillJson;
  121. var json_str = """[
  122. "Glengarry",
  123. "Gladstone",
  124. "Strathern",
  125. "Richmond",
  126. "Georgetown"
  127. ]""";
  128. var suburbs = new JsonElement.from_string(json_str)
  129. .assert_as&lt;JsonArray&gt;()
  130. .as_strings()
  131. .to_array();
  132. // suburbs.length == 5, suburbs[0] == "Glengarry"</code></pre>
  133. <figcaption>From <code>src/tests/Integration/Json.vala</code> — a document becomes a typed Vala array in four calls.</figcaption>
  134. </figure>
  135. <p>Objects read by key, with nullable getters that tell you what is actually there:</p>
  136. <figure class="code-plate">
  137. <pre><code>var obj = new JsonElement.from_string("""
  138. { "name": "Aurora", "age": 27, "active": true }
  139. """).assert_as&lt;JsonObject&gt;();
  140. string? name = obj.get_string("name");
  141. int64? age = obj.get_integer("age");
  142. bool? active = obj.get_bool("active");
  143. double? height = obj.get_double("height"); // null — absent keys answer null</code></pre>
  144. <figcaption>From <code>src/lib/Object.vala</code> — <code>get_array</code>, <code>get_object</code>, <code>try_get</code> and <code>has</code> complete the set.</figcaption>
  145. </figure>
  146. <p>Because documents are Enumerables, the whole modifier vocabulary applies. Select the fields you want from every record in an array of objects; filter objects on their contents; hand the result to anything that consumes a sequence.</p>
  147. <p>Scalars and whole classes map onto the same representation:</p>
  148. <figure class="code-plate">
  149. <pre><code>// A GObject property becomes a JSON number, faithfully
  150. var v = Value(typeof(int64));
  151. v.set_int64(99);
  152. var j = new JsonElement.from_element(new ValueElement(v));
  153. assert(j.stringify() == "99");</code></pre>
  154. <figcaption>From <code>src/tests/Integration/FromElement.vala</code> — the regression tests for scalar dispatch, including <code>int64</code> precision at 2⁵³&nbsp;+&nbsp;1.</figcaption>
  155. </figure>
  156. <p>For line-delimited streams — logs, exports, model output — the JSON Lines classes keep memory flat:</p>
  157. <figure class="code-plate">
  158. <pre><code>// Reading: one element at a time, or as a lazy Enumerable
  159. var input = new JsonlInputStream.from_file(File.new_for_path("events.jsonl"));
  160. JsonElement? element = input.read_next();
  161. // Writing
  162. var output = new JsonlOutputStream(stream);
  163. output.write(element);
  164. output.write_all(elements);</code></pre>
  165. <figcaption>From <code>src/lib/Jsonl.vala</code>.</figcaption>
  166. </figure>
  167. <header class="section-head" id="package">
  168. <p class="kicker"><span>Package &amp; source</span></p>
  169. <h2>The ledger</h2>
  170. </header>
  171. <dl class="docs-package">
  172. <div><dt>Version</dt><dd><code>0.1</code> (from <code>MANIFEST.usm</code>)</dd></div>
  173. <div><dt>Licence</dt><dd>LGPL-3.0-or-later — free to run, study, share and improve; the LGPL keeps it free to link from any program.</dd></div>
  174. <div><dt>Package</dt><dd><code>usm install invercargill-json</code></dd></div>
  175. <div><dt>Provides</dt><dd><code>libinvercargill-json.so</code>, <code>invercargill-json.h</code>, <code>invercargill-json.vapi</code> + <code>.deps</code>, <code>invercargill_json-1.0.gir</code>, <code>invercargill_json-1.0.typelib</code>, <code>invercargill-json.pc</code></dd></div>
  176. <div><dt>Needs at runtime</dt><dd>GLib, GObject, Gio, json-glib, and <code>libinvercargill-1.so</code> — its reason for being.</dd></div>
  177. <div><dt>Source</dt><dd>The repository <code>Tilo15/Invercargill-Json</code> on the Astrologue forge (git over ssh, port 222). Free software: the licence guarantees your right to the source.</dd></div>
  178. </dl>
  179. <nav class="docs-siblings" aria-label="Neighbours in the catalogue">
  180. <p>Its neighbours:</p>
  181. <ul>
  182. <li><a href="../invercargill/">Invercargill</a></li>
  183. <li><a href="../inversion/">Inversion</a></li>
  184. <li><a href="../statum/">Statum</a></li>
  185. </ul>
  186. </nav>
  187. <nav class="docs-pager" aria-label="Project pages">
  188. <a class="docs-pager__link docs-pager__link--prev" href="../invercargill/">
  189. <span>Previous</span>
  190. <strong>Invercargill</strong>
  191. </a>
  192. <p class="docs-pager__up"><a href="../">All eleven</a></p>
  193. <a class="docs-pager__link docs-pager__link--next" href="../inversion/">
  194. <span>Next in the catalogue</span>
  195. <strong>Inversion</strong>
  196. </a>
  197. </nav>
  198. </div>
  199. </div>
  200. </section>
  201. </main>
  202. <footer class="site-footer">
  203. <div class="container">
  204. <div class="footer-grid">
  205. <div class="foot-brand">
  206. <img class="brand__logo brand__logo--dark" src="../../assets/img/astrologue-dark.png" width="392" height="89" alt="Astrologue">
  207. <p>An operating system for change — kept for self sufficiency, resilience, and software freedom, so regular people can hold the power of general purpose computers in their own hands.</p>
  208. </div>
  209. <nav aria-label="The four freedoms">
  210. <p class="foot-title">The Four Freedoms</p>
  211. <ol class="freedoms">
  212. <li><strong>Run</strong> the software as you wish, for any purpose.</li>
  213. <li><strong>Study</strong> the source and change it to do your computing as you wish.</li>
  214. <li><strong>Share</strong> copies so you can help others.</li>
  215. <li><strong>Modify</strong> and publish your versions so everyone benefits.</li>
  216. </ol>
  217. </nav>
  218. <nav aria-label="Site">
  219. <p class="foot-title">Site</p>
  220. <ul class="foot-list">
  221. <li><a href="../../">Home</a></li>
  222. <li><a href="../../#news">News</a></li>
  223. <li><a href="../../#download">Download</a></li>
  224. <li><a href="../">Developer</a></li>
  225. </ul>
  226. </nav>
  227. </div>
  228. <p class="colophon">Set in Cinzel and EB Garamond (SIL Open Font License). Astrologue is free software, licensed GPL-3.0-or-later: take it, tend it, pass it on. The libraries are LGPL-3.0-or-later, so they remain free to link.</p>
  229. </div>
  230. </footer>
  231. </body>
  232. </html>