feat: add example scripts for argparse, bytes, dataset, html, markdown, uuid, wdantic, and web chat modules

Add comprehensive demo scripts showcasing the usage of multiple Wren modules including argument parsing, byte manipulation, in-memory dataset operations, HTML encoding/slugification, markdown-to-HTML conversion, UUID generation/validation, schema validation with wdantic, and a full web chat application with REST endpoints.
This commit is contained in:
2026-01-24 22:40:22 +00:00
parent 0a65272f80
commit 5a4054ec66
105 changed files with 23275 additions and 94 deletions
+255
View File
@@ -0,0 +1,255 @@
<!DOCTYPE html>
<!-- retoor <retoor@molodetz.nl> -->
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>json - Wren-CLI Manual</title>
<link rel="stylesheet" href="../css/style.css">
</head>
<body>
<button class="mobile-menu-toggle">Menu</button>
<div class="container">
<aside class="sidebar">
<div class="sidebar-header">
<h1><a href="../index.html">Wren-CLI</a></h1>
<div class="version">v0.4.0</div>
</div>
<nav class="sidebar-nav">
<div class="section">
<span class="section-title">Getting Started</span>
<ul>
<li><a href="../getting-started/index.html">Overview</a></li>
<li><a href="../getting-started/installation.html">Installation</a></li>
<li><a href="../getting-started/first-script.html">First Script</a></li>
<li><a href="../getting-started/repl.html">Using the REPL</a></li>
</ul>
</div>
<div class="section">
<span class="section-title">Language</span>
<ul>
<li><a href="../language/index.html">Syntax Overview</a></li>
<li><a href="../language/classes.html">Classes</a></li>
<li><a href="../language/methods.html">Methods</a></li>
<li><a href="../language/control-flow.html">Control Flow</a></li>
<li><a href="../language/fibers.html">Fibers</a></li>
<li><a href="../language/modules.html">Modules</a></li>
</ul>
</div>
<div class="section">
<span class="section-title">API Reference</span>
<ul>
<li><a href="index.html">Overview</a></li>
<li><a href="http.html">http</a></li>
<li><a href="websocket.html">websocket</a></li>
<li><a href="tls.html">tls</a></li>
<li><a href="net.html">net</a></li>
<li><a href="dns.html">dns</a></li>
<li><a href="json.html" class="active">json</a></li>
<li><a href="base64.html">base64</a></li>
<li><a href="regex.html">regex</a></li>
<li><a href="jinja.html">jinja</a></li>
<li><a href="crypto.html">crypto</a></li>
<li><a href="os.html">os</a></li>
<li><a href="env.html">env</a></li>
<li><a href="signal.html">signal</a></li>
<li><a href="subprocess.html">subprocess</a></li>
<li><a href="sqlite.html">sqlite</a></li>
<li><a href="datetime.html">datetime</a></li>
<li><a href="timer.html">timer</a></li>
<li><a href="io.html">io</a></li>
<li><a href="scheduler.html">scheduler</a></li>
<li><a href="math.html">math</a></li>
</ul>
</div>
<div class="section">
<span class="section-title">Tutorials</span>
<ul>
<li><a href="../tutorials/index.html">Tutorial List</a></li>
</ul>
</div>
<div class="section">
<span class="section-title">How-To Guides</span>
<ul>
<li><a href="../howto/index.html">How-To List</a></li>
</ul>
</div>
</nav>
</aside>
<main class="content">
<nav class="breadcrumb">
<a href="../index.html">Home</a>
<span class="separator">/</span>
<a href="index.html">API Reference</a>
<span class="separator">/</span>
<span>json</span>
</nav>
<article>
<h1>json</h1>
<p>The <code>json</code> module provides JSON parsing and stringification. It uses the cJSON library for parsing and implements stringify in Wren.</p>
<pre><code>import "json" for Json</code></pre>
<h2>Json Class</h2>
<div class="class-header">
<h3>Json</h3>
<p>JSON parsing and stringification</p>
</div>
<h3>Static Methods</h3>
<div class="method-signature">
<span class="method-name">Json.parse</span>(<span class="param">string</span>) → <span class="type">Map|List|String|Num|Bool|null</span>
</div>
<p>Parses a JSON string and returns the corresponding Wren value.</p>
<ul class="param-list">
<li><span class="param-name">string</span> <span class="param-type">(String)</span> - JSON string to parse</li>
<li><span class="returns">Returns:</span> Parsed value (Map, List, String, Num, Bool, or null)</li>
</ul>
<pre><code>var data = Json.parse('{"name": "Alice", "age": 30}')
System.print(data["name"]) // Alice
System.print(data["age"]) // 30
var list = Json.parse('[1, 2, 3]')
System.print(list[0]) // 1</code></pre>
<div class="method-signature">
<span class="method-name">Json.stringify</span>(<span class="param">value</span>) → <span class="type">String</span>
</div>
<p>Converts a Wren value to a JSON string (compact, no whitespace).</p>
<ul class="param-list">
<li><span class="param-name">value</span> <span class="param-type">(any)</span> - Value to stringify</li>
<li><span class="returns">Returns:</span> JSON string</li>
</ul>
<pre><code>var json = Json.stringify({"name": "Alice", "age": 30})
System.print(json) // {"name":"Alice","age":30}</code></pre>
<div class="method-signature">
<span class="method-name">Json.stringify</span>(<span class="param">value</span>, <span class="param">indent</span>) → <span class="type">String</span>
</div>
<p>Converts a Wren value to a formatted JSON string with indentation.</p>
<ul class="param-list">
<li><span class="param-name">value</span> <span class="param-type">(any)</span> - Value to stringify</li>
<li><span class="param-name">indent</span> <span class="param-type">(Num|String)</span> - Number of spaces or indent string</li>
<li><span class="returns">Returns:</span> Formatted JSON string</li>
</ul>
<pre><code>var json = Json.stringify({"name": "Alice"}, 2)
System.print(json)
// {
// "name": "Alice"
// }
var json2 = Json.stringify({"name": "Bob"}, "\t")
// Uses tab for indentation</code></pre>
<h2>Type Mapping</h2>
<table>
<tr>
<th>JSON Type</th>
<th>Wren Type</th>
</tr>
<tr>
<td>object</td>
<td>Map</td>
</tr>
<tr>
<td>array</td>
<td>List</td>
</tr>
<tr>
<td>string</td>
<td>String</td>
</tr>
<tr>
<td>number</td>
<td>Num</td>
</tr>
<tr>
<td>true/false</td>
<td>Bool</td>
</tr>
<tr>
<td>null</td>
<td>null</td>
</tr>
</table>
<h2>Examples</h2>
<h3>Parsing JSON</h3>
<pre><code>import "json" for Json
var jsonString = '{"users": [{"name": "Alice"}, {"name": "Bob"}]}'
var data = Json.parse(jsonString)
for (user in data["users"]) {
System.print("User: %(user["name"])")
}</code></pre>
<h3>Building and Stringifying</h3>
<pre><code>import "json" for Json
var data = {
"name": "Product",
"price": 29.99,
"tags": ["electronics", "sale"],
"inStock": true,
"metadata": null
}
System.print(Json.stringify(data, 2))</code></pre>
<h3>Nested Structures</h3>
<pre><code>import "json" for Json
var config = {
"server": {
"host": "localhost",
"port": 8080
},
"database": {
"url": "sqlite://data.db"
}
}
var json = Json.stringify(config)
System.print(json)
var parsed = Json.parse(json)
System.print(parsed["server"]["port"]) // 8080</code></pre>
<h3>Special Values</h3>
<pre><code>import "json" for Json
var special = {
"infinity": 1/0,
"nan": 0/0
}
System.print(Json.stringify(special))
// {"infinity":null,"nan":null}
// Infinity and NaN are converted to null</code></pre>
<div class="admonition note">
<div class="admonition-title">Note</div>
<p>Map keys are converted to strings in JSON output. Non-string keys will have their <code>toString</code> method called.</p>
</div>
<div class="admonition warning">
<div class="admonition-title">Warning</div>
<p>Invalid JSON strings will cause a runtime error. Use <code>Fiber.try()</code> to catch parsing errors.</p>
</div>
</article>
<footer class="page-footer">
<a href="dns.html" class="prev">dns</a>
<a href="base64.html" class="next">base64</a>
</footer>
</main>
</div>
<script src="../js/main.js"></script>
</body>
</html>