[{"data":1,"prerenderedAt":786},["ShallowReactive",2],{"post-/blog/json-testing":3,"related-/blog/json-testing":190},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"category":11,"keywords":12,"body":16,"_type":184,"_id":185,"_source":186,"_file":187,"_stem":188,"_extension":189},"/blog/json-testing","blog",false,"","JSON 测试数据与断言","JSON 用于测试夹具与 API 断言，本文介绍组织、Mock 与断言技巧。","2026-08-19","场景",[13,14,15],"json测试","测试数据","json断言",{"type":17,"children":18,"toc":176},"root",[19,27,33,39,44,49,54,59,133,138,160,165,170],{"type":20,"tag":21,"props":22,"children":24},"element","h1",{"id":23},"json-测试数据与断言",[25],{"type":26,"value":8},"text",{"type":20,"tag":28,"props":29,"children":30},"p",{},[31],{"type":26,"value":32},"JSON 常用作测试夹具（fixture）与 API 断言数据，便于组织与维护。",{"type":20,"tag":34,"props":35,"children":37},"h2",{"id":36},"夹具组织",[38],{"type":26,"value":36},{"type":20,"tag":28,"props":40,"children":41},{},[42],{"type":26,"value":43},"按场景分 JSON 文件，测试时加载作为输入或期望输出。",{"type":20,"tag":34,"props":45,"children":47},{"id":46},"断言",[48],{"type":26,"value":46},{"type":20,"tag":28,"props":50,"children":51},{},[52],{"type":26,"value":53},"用 JSONPath 或深度比较断言响应，忽略可变字段（时间、ID）。",{"type":20,"tag":34,"props":55,"children":57},{"id":56},"代码示例",[58],{"type":26,"value":56},{"type":20,"tag":60,"props":61,"children":65},"pre",{"className":62,"code":63,"language":64,"meta":7,"style":7},"language-json shiki shiki-themes github-dark","{\"expected\": {\"status\": \"ok\", \"code\": 0}}\n","json",[66],{"type":20,"tag":67,"props":68,"children":69},"code",{"__ignoreMap":7},[70],{"type":20,"tag":71,"props":72,"children":75},"span",{"class":73,"line":74},"line",1,[76,82,88,93,98,103,109,114,119,123,128],{"type":20,"tag":71,"props":77,"children":79},{"style":78},"--shiki-default:#E1E4E8",[80],{"type":26,"value":81},"{",{"type":20,"tag":71,"props":83,"children":85},{"style":84},"--shiki-default:#79B8FF",[86],{"type":26,"value":87},"\"expected\"",{"type":20,"tag":71,"props":89,"children":90},{"style":78},[91],{"type":26,"value":92},": {",{"type":20,"tag":71,"props":94,"children":95},{"style":84},[96],{"type":26,"value":97},"\"status\"",{"type":20,"tag":71,"props":99,"children":100},{"style":78},[101],{"type":26,"value":102},": ",{"type":20,"tag":71,"props":104,"children":106},{"style":105},"--shiki-default:#9ECBFF",[107],{"type":26,"value":108},"\"ok\"",{"type":20,"tag":71,"props":110,"children":111},{"style":78},[112],{"type":26,"value":113},", ",{"type":20,"tag":71,"props":115,"children":116},{"style":84},[117],{"type":26,"value":118},"\"code\"",{"type":20,"tag":71,"props":120,"children":121},{"style":78},[122],{"type":26,"value":102},{"type":20,"tag":71,"props":124,"children":125},{"style":84},[126],{"type":26,"value":127},"0",{"type":20,"tag":71,"props":129,"children":130},{"style":78},[131],{"type":26,"value":132},"}}\n",{"type":20,"tag":34,"props":134,"children":136},{"id":135},"推荐在线工具",[137],{"type":26,"value":135},{"type":20,"tag":139,"props":140,"children":141},"ul",{},[142,152],{"type":20,"tag":143,"props":144,"children":145},"li",{},[146],{"type":20,"tag":147,"props":148,"children":150},"a",{"href":149},"/mock",[151],{"type":26,"value":149},{"type":20,"tag":143,"props":153,"children":154},{},[155],{"type":20,"tag":147,"props":156,"children":158},{"href":157},"/diff",[159],{"type":26,"value":157},{"type":20,"tag":34,"props":161,"children":163},{"id":162},"小结",[164],{"type":26,"value":162},{"type":20,"tag":28,"props":166,"children":167},{},[168],{"type":26,"value":169},"JSON 用于测试夹具与 API 断言，本文介绍组织、Mock 与断言技巧。 JSONDog 提供全套 JSON 在线工具，纯前端、零上传、中英双语，欢迎免费使用。",{"type":20,"tag":171,"props":172,"children":173},"style",{},[174],{"type":26,"value":175},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":7,"searchDepth":177,"depth":177,"links":178},2,[179,180,181,182,183],{"id":36,"depth":177,"text":36},{"id":46,"depth":177,"text":46},{"id":56,"depth":177,"text":56},{"id":135,"depth":177,"text":135},{"id":162,"depth":177,"text":162},"markdown","content:blog:json-testing.md","content","blog/json-testing.md","blog/json-testing","md",[191,345,484,648],{"_path":192,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":193,"description":194,"date":10,"category":11,"keywords":195,"body":199,"_type":184,"_id":342,"_source":186,"_file":343,"_stem":344,"_extension":189},"/blog/json-as-config","JSON 作为配置文件","JSON 常用作配置文件，但不支持注释，可考虑 JSON5 或 JSONC 替代。",[196,197,198],"json配置","json config","jsonc",{"type":17,"children":200,"toc":335},[201,206,211,216,221,226,231,235,299,303,322,326,331],{"type":20,"tag":21,"props":202,"children":204},{"id":203},"json-作为配置文件",[205],{"type":26,"value":193},{"type":20,"tag":28,"props":207,"children":208},{},[209],{"type":26,"value":210},"JSON 常用作配置文件（如 tsconfig、package.json），但不支持注释，编辑不便。",{"type":20,"tag":34,"props":212,"children":214},{"id":213},"优缺点",[215],{"type":26,"value":213},{"type":20,"tag":28,"props":217,"children":218},{},[219],{"type":26,"value":220},"优点：标准、解析快、跨语言；缺点：无注释、无多行字符串、尾逗号非法。",{"type":20,"tag":34,"props":222,"children":224},{"id":223},"替代方案",[225],{"type":26,"value":223},{"type":20,"tag":28,"props":227,"children":228},{},[229],{"type":26,"value":230},"JSON5、JSONC（带注释）、YAML、TOML 更适合人工编辑的配置。",{"type":20,"tag":34,"props":232,"children":233},{"id":56},[234],{"type":26,"value":56},{"type":20,"tag":60,"props":236,"children":238},{"className":62,"code":237,"language":64,"meta":7,"style":7},"{\n  \"compilerOptions\": {\n    \"target\": \"es2020\"\n  }\n}\n",[239],{"type":20,"tag":67,"props":240,"children":241},{"__ignoreMap":7},[242,250,263,281,290],{"type":20,"tag":71,"props":243,"children":244},{"class":73,"line":74},[245],{"type":20,"tag":71,"props":246,"children":247},{"style":78},[248],{"type":26,"value":249},"{\n",{"type":20,"tag":71,"props":251,"children":252},{"class":73,"line":177},[253,258],{"type":20,"tag":71,"props":254,"children":255},{"style":84},[256],{"type":26,"value":257},"  \"compilerOptions\"",{"type":20,"tag":71,"props":259,"children":260},{"style":78},[261],{"type":26,"value":262},": {\n",{"type":20,"tag":71,"props":264,"children":266},{"class":73,"line":265},3,[267,272,276],{"type":20,"tag":71,"props":268,"children":269},{"style":84},[270],{"type":26,"value":271},"    \"target\"",{"type":20,"tag":71,"props":273,"children":274},{"style":78},[275],{"type":26,"value":102},{"type":20,"tag":71,"props":277,"children":278},{"style":105},[279],{"type":26,"value":280},"\"es2020\"\n",{"type":20,"tag":71,"props":282,"children":284},{"class":73,"line":283},4,[285],{"type":20,"tag":71,"props":286,"children":287},{"style":78},[288],{"type":26,"value":289},"  }\n",{"type":20,"tag":71,"props":291,"children":293},{"class":73,"line":292},5,[294],{"type":20,"tag":71,"props":295,"children":296},{"style":78},[297],{"type":26,"value":298},"}\n",{"type":20,"tag":34,"props":300,"children":301},{"id":135},[302],{"type":26,"value":135},{"type":20,"tag":139,"props":304,"children":305},{},[306,314],{"type":20,"tag":143,"props":307,"children":308},{},[309],{"type":20,"tag":147,"props":310,"children":312},{"href":311},"/format",[313],{"type":26,"value":311},{"type":20,"tag":143,"props":315,"children":316},{},[317],{"type":20,"tag":147,"props":318,"children":320},{"href":319},"/validate",[321],{"type":26,"value":319},{"type":20,"tag":34,"props":323,"children":324},{"id":162},[325],{"type":26,"value":162},{"type":20,"tag":28,"props":327,"children":328},{},[329],{"type":26,"value":330},"JSON 常用作配置文件，但不支持注释，可考虑 JSON5 或 JSONC 替代。 JSONDog 提供全套 JSON 在线工具，纯前端、零上传、中英双语，欢迎免费使用。",{"type":20,"tag":171,"props":332,"children":333},{},[334],{"type":26,"value":175},{"title":7,"searchDepth":177,"depth":177,"links":336},[337,338,339,340,341],{"id":213,"depth":177,"text":213},{"id":223,"depth":177,"text":223},{"id":56,"depth":177,"text":56},{"id":135,"depth":177,"text":135},{"id":162,"depth":177,"text":162},"content:blog:json-as-config.md","blog/json-as-config.md","blog/json-as-config",{"_path":346,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":347,"description":348,"date":10,"category":11,"keywords":349,"body":353,"_type":184,"_id":481,"_source":186,"_file":482,"_stem":483,"_extension":189},"/blog/json-caching","JSON 缓存策略","JSON 响应可缓存于 CDN、Redis、本地，本文介绍缓存键设计与失效策略。",[350,351,352],"json缓存","api缓存","redis json",{"type":17,"children":354,"toc":474},[355,360,365,370,375,380,385,389,439,443,461,465,470],{"type":20,"tag":21,"props":356,"children":358},{"id":357},"json-缓存策略",[359],{"type":26,"value":347},{"type":20,"tag":28,"props":361,"children":362},{},[363],{"type":26,"value":364},"JSON 响应缓存可大幅提升性能，需合理设计缓存键与失效策略。",{"type":20,"tag":34,"props":366,"children":368},{"id":367},"缓存层",[369],{"type":26,"value":367},{"type":20,"tag":28,"props":371,"children":372},{},[373],{"type":26,"value":374},"CDN 缓存静态 JSON、Redis 缓存热点接口、浏览器缓存带 ETag。",{"type":20,"tag":34,"props":376,"children":378},{"id":377},"失效策略",[379],{"type":26,"value":377},{"type":20,"tag":28,"props":381,"children":382},{},[383],{"type":26,"value":384},"TTL 过期、版本号键、主动清除，注意一致性。",{"type":20,"tag":34,"props":386,"children":387},{"id":56},[388],{"type":26,"value":56},{"type":20,"tag":60,"props":390,"children":392},{"className":62,"code":391,"language":64,"meta":7,"style":7},"{\"key\": \"user:1:profile\", \"ttl\": 3600}\n",[393],{"type":20,"tag":67,"props":394,"children":395},{"__ignoreMap":7},[396],{"type":20,"tag":71,"props":397,"children":398},{"class":73,"line":74},[399,403,408,412,417,421,426,430,435],{"type":20,"tag":71,"props":400,"children":401},{"style":78},[402],{"type":26,"value":81},{"type":20,"tag":71,"props":404,"children":405},{"style":84},[406],{"type":26,"value":407},"\"key\"",{"type":20,"tag":71,"props":409,"children":410},{"style":78},[411],{"type":26,"value":102},{"type":20,"tag":71,"props":413,"children":414},{"style":105},[415],{"type":26,"value":416},"\"user:1:profile\"",{"type":20,"tag":71,"props":418,"children":419},{"style":78},[420],{"type":26,"value":113},{"type":20,"tag":71,"props":422,"children":423},{"style":84},[424],{"type":26,"value":425},"\"ttl\"",{"type":20,"tag":71,"props":427,"children":428},{"style":78},[429],{"type":26,"value":102},{"type":20,"tag":71,"props":431,"children":432},{"style":84},[433],{"type":26,"value":434},"3600",{"type":20,"tag":71,"props":436,"children":437},{"style":78},[438],{"type":26,"value":298},{"type":20,"tag":34,"props":440,"children":441},{"id":135},[442],{"type":26,"value":135},{"type":20,"tag":139,"props":444,"children":445},{},[446,454],{"type":20,"tag":143,"props":447,"children":448},{},[449],{"type":20,"tag":147,"props":450,"children":452},{"href":451},"/minify",[453],{"type":26,"value":451},{"type":20,"tag":143,"props":455,"children":456},{},[457],{"type":20,"tag":147,"props":458,"children":459},{"href":311},[460],{"type":26,"value":311},{"type":20,"tag":34,"props":462,"children":463},{"id":162},[464],{"type":26,"value":162},{"type":20,"tag":28,"props":466,"children":467},{},[468],{"type":26,"value":469},"JSON 响应可缓存于 CDN、Redis、本地，本文介绍缓存键设计与失效策略。 JSONDog 提供全套 JSON 在线工具，纯前端、零上传、中英双语，欢迎免费使用。",{"type":20,"tag":171,"props":471,"children":472},{},[473],{"type":26,"value":175},{"title":7,"searchDepth":177,"depth":177,"links":475},[476,477,478,479,480],{"id":367,"depth":177,"text":367},{"id":377,"depth":177,"text":377},{"id":56,"depth":177,"text":56},{"id":135,"depth":177,"text":135},{"id":162,"depth":177,"text":162},"content:blog:json-caching.md","blog/json-caching.md","blog/json-caching",{"_path":485,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":486,"description":487,"date":10,"category":11,"keywords":488,"body":492,"_type":184,"_id":645,"_source":186,"_file":646,"_stem":647,"_extension":189},"/blog/json-form-data","JSON 与表单数据转换","前端表单常需与 JSON 互转，本文介绍序列化、嵌套表单与提交技巧。",[489,490,491],"json表单","form json","表单序列化",{"type":17,"children":493,"toc":638},[494,499,504,509,519,524,529,533,603,607,625,629,634],{"type":20,"tag":21,"props":495,"children":497},{"id":496},"json-与表单数据转换",[498],{"type":26,"value":486},{"type":20,"tag":28,"props":500,"children":501},{},[502],{"type":26,"value":503},"前端表单数据常需转为 JSON 提交 API，或将 JSON 回填表单，需处理嵌套与数组。",{"type":20,"tag":34,"props":505,"children":507},{"id":506},"转换方式",[508],{"type":26,"value":506},{"type":20,"tag":28,"props":510,"children":511},{},[512,514,517],{"type":26,"value":513},"FormData 遍历构建对象、name 用点路径表达嵌套、数组用 ",{"type":20,"tag":71,"props":515,"children":516},{},[],{"type":26,"value":518}," 后缀。",{"type":20,"tag":34,"props":520,"children":522},{"id":521},"库推荐",[523],{"type":26,"value":521},{"type":20,"tag":28,"props":525,"children":526},{},[527],{"type":26,"value":528},"qs、form-serialize、或框架内置（如 Vue v-model）。",{"type":20,"tag":34,"props":530,"children":531},{"id":56},[532],{"type":26,"value":56},{"type":20,"tag":60,"props":534,"children":536},{"className":62,"code":535,"language":64,"meta":7,"style":7},"{\"user\": {\"name\": \"x\", \"tags\": [\"a\", \"b\"]}}\n",[537],{"type":20,"tag":67,"props":538,"children":539},{"__ignoreMap":7},[540],{"type":20,"tag":71,"props":541,"children":542},{"class":73,"line":74},[543,547,552,556,561,565,570,574,579,584,589,593,598],{"type":20,"tag":71,"props":544,"children":545},{"style":78},[546],{"type":26,"value":81},{"type":20,"tag":71,"props":548,"children":549},{"style":84},[550],{"type":26,"value":551},"\"user\"",{"type":20,"tag":71,"props":553,"children":554},{"style":78},[555],{"type":26,"value":92},{"type":20,"tag":71,"props":557,"children":558},{"style":84},[559],{"type":26,"value":560},"\"name\"",{"type":20,"tag":71,"props":562,"children":563},{"style":78},[564],{"type":26,"value":102},{"type":20,"tag":71,"props":566,"children":567},{"style":105},[568],{"type":26,"value":569},"\"x\"",{"type":20,"tag":71,"props":571,"children":572},{"style":78},[573],{"type":26,"value":113},{"type":20,"tag":71,"props":575,"children":576},{"style":84},[577],{"type":26,"value":578},"\"tags\"",{"type":20,"tag":71,"props":580,"children":581},{"style":78},[582],{"type":26,"value":583},": [",{"type":20,"tag":71,"props":585,"children":586},{"style":105},[587],{"type":26,"value":588},"\"a\"",{"type":20,"tag":71,"props":590,"children":591},{"style":78},[592],{"type":26,"value":113},{"type":20,"tag":71,"props":594,"children":595},{"style":105},[596],{"type":26,"value":597},"\"b\"",{"type":20,"tag":71,"props":599,"children":600},{"style":78},[601],{"type":26,"value":602},"]}}\n",{"type":20,"tag":34,"props":604,"children":605},{"id":135},[606],{"type":26,"value":135},{"type":20,"tag":139,"props":608,"children":609},{},[610,618],{"type":20,"tag":143,"props":611,"children":612},{},[613],{"type":20,"tag":147,"props":614,"children":616},{"href":615},"/flatten",[617],{"type":26,"value":615},{"type":20,"tag":143,"props":619,"children":620},{},[621],{"type":20,"tag":147,"props":622,"children":623},{"href":311},[624],{"type":26,"value":311},{"type":20,"tag":34,"props":626,"children":627},{"id":162},[628],{"type":26,"value":162},{"type":20,"tag":28,"props":630,"children":631},{},[632],{"type":26,"value":633},"前端表单常需与 JSON 互转，本文介绍序列化、嵌套表单与提交技巧。 JSONDog 提供全套 JSON 在线工具，纯前端、零上传、中英双语，欢迎免费使用。",{"type":20,"tag":171,"props":635,"children":636},{},[637],{"type":26,"value":175},{"title":7,"searchDepth":177,"depth":177,"links":639},[640,641,642,643,644],{"id":506,"depth":177,"text":506},{"id":521,"depth":177,"text":521},{"id":56,"depth":177,"text":56},{"id":135,"depth":177,"text":135},{"id":162,"depth":177,"text":162},"content:blog:json-form-data.md","blog/json-form-data.md","blog/json-form-data",{"_path":649,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":650,"description":651,"date":10,"category":11,"keywords":652,"body":656,"_type":184,"_id":783,"_source":186,"_file":784,"_stem":785,"_extension":189},"/blog/json-i18n","JSON 与国际化方案","JSON 是 i18n 资源文件常用格式，按语言分文件，键值映射文案。",[653,654,655],"json i18n","国际化json","多语言json",{"type":17,"children":657,"toc":776},[658,663,668,673,678,683,688,692,742,746,763,767,772],{"type":20,"tag":21,"props":659,"children":661},{"id":660},"json-与国际化方案",[662],{"type":26,"value":650},{"type":20,"tag":28,"props":664,"children":665},{},[666],{"type":26,"value":667},"JSON 是国际化资源文件的常用格式，按语言分文件，键值对映射文案。",{"type":20,"tag":34,"props":669,"children":671},{"id":670},"结构设计",[672],{"type":26,"value":670},{"type":20,"tag":28,"props":674,"children":675},{},[676],{"type":26,"value":677},"按语言分文件（en.json、zh.json），键用点路径或嵌套对象组织命名空间。",{"type":20,"tag":34,"props":679,"children":681},{"id":680},"使用",[682],{"type":26,"value":680},{"type":20,"tag":28,"props":684,"children":685},{},[686],{"type":26,"value":687},"前端 i18n 库加载对应语言 JSON，按键取文案，支持插值与复数。",{"type":20,"tag":34,"props":689,"children":690},{"id":56},[691],{"type":26,"value":56},{"type":20,"tag":60,"props":693,"children":695},{"className":62,"code":694,"language":64,"meta":7,"style":7},"{\"welcome\": \"欢迎\", \"login\": \"登录\"}\n",[696],{"type":20,"tag":67,"props":697,"children":698},{"__ignoreMap":7},[699],{"type":20,"tag":71,"props":700,"children":701},{"class":73,"line":74},[702,706,711,715,720,724,729,733,738],{"type":20,"tag":71,"props":703,"children":704},{"style":78},[705],{"type":26,"value":81},{"type":20,"tag":71,"props":707,"children":708},{"style":84},[709],{"type":26,"value":710},"\"welcome\"",{"type":20,"tag":71,"props":712,"children":713},{"style":78},[714],{"type":26,"value":102},{"type":20,"tag":71,"props":716,"children":717},{"style":105},[718],{"type":26,"value":719},"\"欢迎\"",{"type":20,"tag":71,"props":721,"children":722},{"style":78},[723],{"type":26,"value":113},{"type":20,"tag":71,"props":725,"children":726},{"style":84},[727],{"type":26,"value":728},"\"login\"",{"type":20,"tag":71,"props":730,"children":731},{"style":78},[732],{"type":26,"value":102},{"type":20,"tag":71,"props":734,"children":735},{"style":105},[736],{"type":26,"value":737},"\"登录\"",{"type":20,"tag":71,"props":739,"children":740},{"style":78},[741],{"type":26,"value":298},{"type":20,"tag":34,"props":743,"children":744},{"id":135},[745],{"type":26,"value":135},{"type":20,"tag":139,"props":747,"children":748},{},[749,756],{"type":20,"tag":143,"props":750,"children":751},{},[752],{"type":20,"tag":147,"props":753,"children":754},{"href":311},[755],{"type":26,"value":311},{"type":20,"tag":143,"props":757,"children":758},{},[759],{"type":20,"tag":147,"props":760,"children":761},{"href":319},[762],{"type":26,"value":319},{"type":20,"tag":34,"props":764,"children":765},{"id":162},[766],{"type":26,"value":162},{"type":20,"tag":28,"props":768,"children":769},{},[770],{"type":26,"value":771},"JSON 是 i18n 资源文件常用格式，按语言分文件，键值映射文案。 JSONDog 提供全套 JSON 在线工具，纯前端、零上传、中英双语，欢迎免费使用。",{"type":20,"tag":171,"props":773,"children":774},{},[775],{"type":26,"value":175},{"title":7,"searchDepth":177,"depth":177,"links":777},[778,779,780,781,782],{"id":670,"depth":177,"text":670},{"id":680,"depth":177,"text":680},{"id":56,"depth":177,"text":56},{"id":135,"depth":177,"text":135},{"id":162,"depth":177,"text":162},"content:blog:json-i18n.md","blog/json-i18n.md","blog/json-i18n",1787305467296]