+}</code></pre><p>Now in some other code we can use Cause.encode and Cause.decoder as building blocks. So if we want to decode a list of causes, saying <code>Json.Decode.array(Cause.decoder)</code> will handle it!</p><p>Point is, the goal should be:</p><ol><li>Make small JSON decoders and encoders.</li><li>Snap together these building blocks as needed.</li></ol><p>So say you decide to make the name field more precise. Instead of a <code>string</code>, you want to use codes from the <a href="https://www.who.int/classifications/classification-of-diseases">International Classification of Diseases</a> recommended by the World Health Organization. These <a href="https://icd.who.int/browse10/2016/en">codes</a> are used in a lot of mortality data sets. So it may make sense to make a separate <code>icdCode</code> module with its own <code>IcdCode.encode</code> and <code>IcdCode.decoder</code> that ensure you are working with valid codes. From there, you can use them as building blocks in the <code>Cause</code> module!</p></aside></section><section><header><h3 id="docs"><a href="#docs" class="anchor"></a>Docs</h3></header><dl><dt class="spec type" id="type-value"><a href="#type-value" class="anchor"></a><code><span class="keyword">type</span> <span class="keyword">nonrec</span> value</code><code> = Js.Json.t</code>;</dt></dl><aside><p>Represents a JavaScript value.</p></aside><div class="spec module" id="module-Decode"><a href="#module-Decode" class="anchor"></a><code><span class="keyword">module</span> <a href="Decode">Decode</a>: { ... };</code></div><aside><p>The Decode module. Accessed by <code>Json.Decode.*</code></p></aside><div class="spec module" id="module-Encode"><a href="#module-Encode" class="anchor"></a><code><span class="keyword">module</span> <a href="Encode">Encode</a>: { ... };</code></div><aside><p>The Encode module. Accessed by <code>Json.Encode.*</code></p></aside></section><section><header><h3 id="credit"><a href="#credit" class="anchor"></a>Credit</h3></header><aside><p>This package is a port of <a href="https://package.elm-lang.org/packages/elm/json/latest/">Elm's JSON decoding library</a>.</p><p>When creating this package, I basically went through the docs for the Elm library and implemented a Rescript version. Additional, because it's so well done, the documentation is copied almost verbatim.</p><p>Thanks to Evan Czaplicki (<a href="https://github.com/evancz">@evancz</a>) and all other folks for designing and creating the excellent Elm package!</p></aside></section></div></body></html>
0 commit comments