web.json
req.json + JDoc 校验族(§4.3 请求体绑定;2b Task 0;收编 std/json) 设计: docs/superpowers/specs/2026-09-27-web-framework-design.md §4.3;纪律 §14-1
独立成件(不在 core.ct)的在册理由(task-0-report 实证):core 一旦 use std.json, 其合并态 mf 即含 std/json 的 match 形 decl(Test 恒随 + 私有助手恒随),pkg_refs_walk 不识该形 → 选择性合并翻"保守整模块"回退 → core 的 text(Resp ctor)整并入, 与 view 的 text(El 链)撞名 E5030——view 单测与 view+core 同并入的真实应用形皆炸。 json 域自宿一文件,core/view 合并面保持 HEAD 干净;本件被并入时携带的 std/json pub 面(parse/qtag/qval/esc/jget_/jv_…)与 web 四件无同名,实证 probe 见报告。
json_of = std/json parse 的 Req.body 包装(路径展平 DOM;坏体 ok=false + 空条目, 后续 jd_ 恒 None——校验失败不炸请求循环,422 交由调用点 err_json 统一回形)。 jd_ 收编口径:str/bool 走 qtag/qval 纯函数查询面(零 union 载荷往返回路); i64 走 jget_i64 Result 面(T53 数值保真闭环后为 std/json 唯一 pub 数值面; 原 jnum_i64 结构通道已回切摘除)。整数语法形态限定(小数/指数 → None) 与 I64 域越界 → None 均由 std/jget_i64 原样继承。
pub struct
struct JDoc
| Field | Type |
|---|---|
ok |
Bool |
entries |
List[List[Str]] |
struct Pair
| Field | Type |
|---|---|
k |
Str |
v |
Str |
struct Resp
| Field | Type |
|---|---|
status |
I32 |
headers |
List[Pair] |
body |
Str |
struct JObj
| Field | Type |
|---|---|
parts |
List[Str] |
struct Req[S]
| Field | Type |
|---|---|
method |
Str |
path |
Str |
query |
Str |
body |
Str |
headers |
List[Pair] |
cookies |
List[Pair] |
params |
List[Pair] |
session |
List[Pair] |
state |
S |
pub fn
| Signature | Returns | Description |
|---|---|---|
json_of[S](r: &Req[S]) |
JDoc |
— |
jd_str(d: JDoc, path: Str) |
Option[Str] |
取值:标签须 s;缺路径/null/类型不符 → None |
jd_bool(d: JDoc, path: Str) |
Option[Bool] |
取值:标签须 b 且原文 true/false;缺路径/null/类型不符 → None |
jd_i64(d: JDoc, path: Str) |
Option[I64] |
取值:标签须 n 且整数语法形态(小数/指数/越 I64 域 → None;经 jget_i64 Result 面) |
jd_str_between(d: JDoc, path: Str, lo: I32, hi: I32) |
Option[Str] |
校验族:取值 + 域检查一体,Option 回形(闭区间 [lo, hi],双界含)。 jd_str_between 长度为字节长(同仓 Str.len 全 byte 口径——"中文" 记 6)。 |
jd_i64_between(d: JDoc, path: Str, lo: I64, hi: I64) |
Option[I64] |
— |
html(body: Str) |
Resp |
— |
json(body: Str) |
Resp |
— |
redirect(loc: Str) |
Resp |
— |
status(n: I32, body: Str) |
Resp |
— |
xml(body: Str) |
Resp |
— |
yaml(body: Str) |
Resp |
— |
err_json(n: I32, msg: Str) |
Resp |
— |
attachment(r: Resp, filename: Str) |
Resp |
— |
with(r: Resp, k: Str, v: Str) |
Resp |
— |
with_status(r: Resp, n: I32) |
Resp |
— |
resp_header(r: Resp, k: Str) |
Str |
— |
resp_body(r: Resp) |
Str |
— |
resp_status(r: Resp) |
I32 |
— |
json_obj() |
JObj |
— |
str(b: JObj, k: Str, v: Str) |
JObj |
— |
i64(b: JObj, k: Str, v: I64) |
JObj |
— |
bool(b: JObj, k: Str, v: Bool) |
JObj |
— |
strs(b: JObj, k: Str, xs: List[Str]) |
JObj |
— |
end(b: JObj) |
Str |
— |
end_status(b: JObj, n: I32) |
Resp |
— |
csv_rows(headers: List[Str], rows: List[List[Str]]) |
Str |
— |
req_of[S](method: Str, path: Str, state: S) |
Req[S] |
— |
req_full[S](method: Str, path: Str, body: Str, hdrs: List[Pair], state: S) |
Req[S] |
— |
req_set_params[S](r: &Req[S], params: List[Pair]) |
Req[S] |
— |
req_set_session[S](r: &Req[S], sess: List[Pair]) |
Req[S] |
— |
pdec(s: Str) |
Str |
— |
param[S](r: &Req[S], name: Str) |
Str |
— |
pair_get(ps: List[Pair], k: Str) |
Str |
— |
param_i64[S](r: &Req[S], name: Str) |
Option[I64] |
— |
param_f64[S](r: &Req[S], name: Str) |
Option[F64] |
— |
query[S](r: &Req[S], name: Str) |
Str |
— |
query_all[S](r: &Req[S], name: Str) |
List[Str] |
— |
form[S](r: &Req[S], name: Str) |
Str |
— |
form_all[S](r: &Req[S], name: Str) |
List[Str] |
— |
header[S](r: &Req[S], name: Str) |
Str |
— |
cookie[S](r: &Req[S], name: Str) |
Str |
— |
session[S](r: &Req[S], name: Str) |
Str |
— |