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