1
0
Fork 0
forked from fun/fun

All incomplete examples have been updated and some corrections have been made to the parser to make them work. (0.37.17)

This commit is contained in:
Johannes Findeisen 2025-12-23 20:49:07 +01:00
commit 92aacff71a
41 changed files with 654 additions and 130 deletions

View file

@ -53,7 +53,7 @@ print(len(cfg["users"])) // number of users
// Derive a small summary map
summary = {}
summary["user_count"] = len(cfg["users"])
summary["user_count"] = len(cfg["users"])
summary["first_user_name"] = cfg["users"][1]["name"]
summary["features_enabled"] = cfg["features"]["enabled"]
@ -63,3 +63,45 @@ print(json.stringify(summary, 1))
out_path = "/tmp/fun_complex_out.json"
ok = json.to_file(out_path, cfg, 1)
print(ok) // 1 on success
/* Expected output:
-- JSON: parse from string and pretty print --
Dump:
{"name": Ada, "active": true, "score": 99.5, "count": 42, "tags": [C, Ada, Math], "extra": nil}
Ada
true
42
3
{
"name":"Ada",
"active":true,
"score":99.5,
"count":42,
"tags":[
"C",
"Ada",
"Math"
],
"extra":null
}
-- JSON: load from file, inspect, and save pretty to /tmp --
Dump:
nil
Dump:
{"project": {"name": Fun, "version": 0.27.2, "website": https://fun-lang.xyz, "license": {"name": Apache-2.0, "url": https://opensource.org/license/apache-2-0}}, "features": {"enabled": [arrays, maps, json, pcsc], "experimental": {"repl": true, "sockets": true, "odbc": false, "notes": nil}}, "users": [{"id": 1, "name": Ada, "roles": [admin, math], "active": true, "score": 99.5, "prefs": {"theme": dark, "editor": {"tabWidth": 2, "font": Fira Code}}}, {"id": 2, "name": Linus, "roles": [user, kernel], "active": false, "score": 88, "prefs": {"theme": light, "editor": {"tabWidth": 8, "font": Monospace}}}], "metrics": {"counters": [0, 1, 1, 2, 3, 5, 8], "latency_ms": {"p50": 1.23, "p90": 3.21, "p99": 12.34}, "builds": 1234567890123456789, "last_release_ts": 1732406400000}, "matrix": [[1, 2, 3], [4, 5, 6], [7, 8, 9]], "notes": UTF-8 emojis: 🚀🔥, "null_field": nil}
Fun
0.27.2
2
{
"user_count":2,
"first_user_name":"Linus",
"features_enabled":[
"arrays",
"maps",
"json",
"pcsc"
]
}
1
*/