[{"data":1,"prerenderedAt":774},["ShallowReactive",2],{"post-/blog/json-serialization":3,"related-/blog/json-serialization":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-serialization","blog",false,"","JSON 序列化原理与库","JSON 序列化将对象转为 JSON 字符串，各语言有成熟库，本文介绍原理与选型。","2026-08-19","进阶",[13,14,15],"json序列化","json stringify","序列化库",{"type":17,"children":18,"toc":176},"root",[19,27,33,39,44,49,54,59,134,139,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 序列化指将内存对象转为 JSON 字符串，反序列化则相反，各语言均有成熟库支持。",{"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},"JavaScript 内置 JSON、Java 用 Jackson/Gson、Python 用 json、Go 用 encoding/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},"循环引用、大整数精度丢失、日期格式、Unicode 转义需特别处理。",{"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","JSON.stringify({a:1, b:[2,3]})\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,114,119,124,129],{"type":20,"tag":71,"props":77,"children":79},{"style":78},"--shiki-default:#E1E4E8",[80],{"type":26,"value":81},"JSON.stringify({",{"type":20,"tag":71,"props":83,"children":85},{"style":84},"--shiki-default:#FDAEB7;--shiki-default-font-style:italic",[86],{"type":26,"value":87},"a",{"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:#79B8FF",[97],{"type":26,"value":98},"1",{"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},"b",{"type":20,"tag":71,"props":110,"children":111},{"style":78},[112],{"type":26,"value":113},":[",{"type":20,"tag":71,"props":115,"children":116},{"style":95},[117],{"type":26,"value":118},"2",{"type":20,"tag":71,"props":120,"children":121},{"style":78},[122],{"type":26,"value":123},",",{"type":20,"tag":71,"props":125,"children":126},{"style":95},[127],{"type":26,"value":128},"3",{"type":20,"tag":71,"props":130,"children":131},{"style":78},[132],{"type":26,"value":133},"]})\n",{"type":20,"tag":34,"props":135,"children":137},{"id":136},"推荐在线工具",[138],{"type":26,"value":136},{"type":20,"tag":140,"props":141,"children":142},"ul",{},[143,152],{"type":20,"tag":144,"props":145,"children":146},"li",{},[147],{"type":20,"tag":87,"props":148,"children":150},{"href":149},"/format",[151],{"type":26,"value":149},{"type":20,"tag":144,"props":153,"children":154},{},[155],{"type":20,"tag":87,"props":156,"children":158},{"href":157},"/minify",[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 序列化将对象转为 JSON 字符串，各语言有成熟库，本文介绍原理与选型。 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":136,"depth":177,"text":136},{"id":162,"depth":177,"text":162},"markdown","content:blog:json-serialization.md","content","blog/json-serialization.md","blog/json-serialization","md",[191,372,493,652],{"_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":369,"_source":186,"_file":370,"_stem":371,"_extension":189},"/blog/json-api-spec","JSON:API 规范指南","JSON:API 是 RESTful API 的数据响应规范，统一资源、关系、分页、错误格式。",[196,197,198],"json:api","json api规范","restful",{"type":17,"children":200,"toc":362},[201,206,211,216,221,226,231,235,327,331,349,353,358],{"type":20,"tag":21,"props":202,"children":204},{"id":203},"jsonapi-规范指南",[205],{"type":26,"value":193},{"type":20,"tag":28,"props":207,"children":208},{},[209],{"type":26,"value":210},"JSON:API 是一套构建 RESTful API 数据响应的规范，统一了资源对象、关系、分页与错误的 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},"data 包含资源数组或单对象，relationships 描述关联，included 包含关联资源，meta 存元信息。",{"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},"统一格式减少约定成本，客户端可通用化处理。",{"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},"{\"data\": [{\"type\": \"user\", \"id\": \"1\", \"attributes\": {\"name\": \"x\"}}]}\n",[239],{"type":20,"tag":67,"props":240,"children":241},{"__ignoreMap":7},[242],{"type":20,"tag":71,"props":243,"children":244},{"class":73,"line":74},[245,250,255,260,265,270,276,280,285,289,294,298,303,308,313,317,322],{"type":20,"tag":71,"props":246,"children":247},{"style":78},[248],{"type":26,"value":249},"{",{"type":20,"tag":71,"props":251,"children":252},{"style":95},[253],{"type":26,"value":254},"\"data\"",{"type":20,"tag":71,"props":256,"children":257},{"style":78},[258],{"type":26,"value":259},": [{",{"type":20,"tag":71,"props":261,"children":262},{"style":95},[263],{"type":26,"value":264},"\"type\"",{"type":20,"tag":71,"props":266,"children":267},{"style":78},[268],{"type":26,"value":269},": ",{"type":20,"tag":71,"props":271,"children":273},{"style":272},"--shiki-default:#9ECBFF",[274],{"type":26,"value":275},"\"user\"",{"type":20,"tag":71,"props":277,"children":278},{"style":78},[279],{"type":26,"value":103},{"type":20,"tag":71,"props":281,"children":282},{"style":95},[283],{"type":26,"value":284},"\"id\"",{"type":20,"tag":71,"props":286,"children":287},{"style":78},[288],{"type":26,"value":269},{"type":20,"tag":71,"props":290,"children":291},{"style":272},[292],{"type":26,"value":293},"\"1\"",{"type":20,"tag":71,"props":295,"children":296},{"style":78},[297],{"type":26,"value":103},{"type":20,"tag":71,"props":299,"children":300},{"style":95},[301],{"type":26,"value":302},"\"attributes\"",{"type":20,"tag":71,"props":304,"children":305},{"style":78},[306],{"type":26,"value":307},": {",{"type":20,"tag":71,"props":309,"children":310},{"style":95},[311],{"type":26,"value":312},"\"name\"",{"type":20,"tag":71,"props":314,"children":315},{"style":78},[316],{"type":26,"value":269},{"type":20,"tag":71,"props":318,"children":319},{"style":272},[320],{"type":26,"value":321},"\"x\"",{"type":20,"tag":71,"props":323,"children":324},{"style":78},[325],{"type":26,"value":326},"}}]}\n",{"type":20,"tag":34,"props":328,"children":329},{"id":136},[330],{"type":26,"value":136},{"type":20,"tag":140,"props":332,"children":333},{},[334,341],{"type":20,"tag":144,"props":335,"children":336},{},[337],{"type":20,"tag":87,"props":338,"children":339},{"href":149},[340],{"type":26,"value":149},{"type":20,"tag":144,"props":342,"children":343},{},[344],{"type":20,"tag":87,"props":345,"children":347},{"href":346},"/validate",[348],{"type":26,"value":346},{"type":20,"tag":34,"props":350,"children":351},{"id":162},[352],{"type":26,"value":162},{"type":20,"tag":28,"props":354,"children":355},{},[356],{"type":26,"value":357},"JSON:API 是 RESTful API 的数据响应规范，统一资源、关系、分页、错误格式。 JSONDog 提供全套 JSON 在线工具，纯前端、零上传、中英双语，欢迎免费使用。",{"type":20,"tag":171,"props":359,"children":360},{},[361],{"type":26,"value":175},{"title":7,"searchDepth":177,"depth":177,"links":363},[364,365,366,367,368],{"id":213,"depth":177,"text":213},{"id":223,"depth":177,"text":223},{"id":56,"depth":177,"text":56},{"id":136,"depth":177,"text":136},{"id":162,"depth":177,"text":162},"content:blog:json-api-spec.md","blog/json-api-spec.md","blog/json-api-spec",{"_path":373,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":374,"description":375,"date":10,"category":11,"keywords":376,"body":380,"_type":184,"_id":490,"_source":186,"_file":491,"_stem":492,"_extension":189},"/blog/json-deserialization","JSON 反序列化注意事项","JSON 反序列化将字符串转为对象，需注意类型丢失、精度、安全与错误处理。",[377,378,379],"json反序列化","json parse","反序列化",{"type":17,"children":381,"toc":483},[382,387,392,397,402,407,412,416,449,453,470,474,479],{"type":20,"tag":21,"props":383,"children":385},{"id":384},"json-反序列化注意事项",[386],{"type":26,"value":374},{"type":20,"tag":28,"props":388,"children":389},{},[390],{"type":26,"value":391},"JSON 反序列化将 JSON 字符串解析为内存对象，过程中需注意类型、精度与安全。",{"type":20,"tag":34,"props":393,"children":395},{"id":394},"常见问题",[396],{"type":26,"value":394},{"type":20,"tag":28,"props":398,"children":399},{},[400],{"type":26,"value":401},"大整数精度丢失（JS Number 限制）、日期需手动转换、类型信息丢失、非法 JSON 抛错。",{"type":20,"tag":34,"props":403,"children":405},{"id":404},"安全",[406],{"type":26,"value":404},{"type":20,"tag":28,"props":408,"children":409},{},[410],{"type":26,"value":411},"避免 eval 解析（注入风险），使用 JSON.parse；注意原型链污染。",{"type":20,"tag":34,"props":413,"children":414},{"id":56},[415],{"type":26,"value":56},{"type":20,"tag":60,"props":417,"children":419},{"className":62,"code":418,"language":64,"meta":7,"style":7},"JSON.parse('{\"a\":1}')\n",[420],{"type":20,"tag":67,"props":421,"children":422},{"__ignoreMap":7},[423],{"type":20,"tag":71,"props":424,"children":425},{"class":73,"line":74},[426,431,436,440,444],{"type":20,"tag":71,"props":427,"children":428},{"style":78},[429],{"type":26,"value":430},"JSON.parse('{",{"type":20,"tag":71,"props":432,"children":433},{"style":95},[434],{"type":26,"value":435},"\"a\"",{"type":20,"tag":71,"props":437,"children":438},{"style":78},[439],{"type":26,"value":92},{"type":20,"tag":71,"props":441,"children":442},{"style":95},[443],{"type":26,"value":98},{"type":20,"tag":71,"props":445,"children":446},{"style":78},[447],{"type":26,"value":448},"}')\n",{"type":20,"tag":34,"props":450,"children":451},{"id":136},[452],{"type":26,"value":136},{"type":20,"tag":140,"props":454,"children":455},{},[456,463],{"type":20,"tag":144,"props":457,"children":458},{},[459],{"type":20,"tag":87,"props":460,"children":461},{"href":346},[462],{"type":26,"value":346},{"type":20,"tag":144,"props":464,"children":465},{},[466],{"type":20,"tag":87,"props":467,"children":468},{"href":149},[469],{"type":26,"value":149},{"type":20,"tag":34,"props":471,"children":472},{"id":162},[473],{"type":26,"value":162},{"type":20,"tag":28,"props":475,"children":476},{},[477],{"type":26,"value":478},"JSON 反序列化将字符串转为对象，需注意类型丢失、精度、安全与错误处理。 JSONDog 提供全套 JSON 在线工具，纯前端、零上传、中英双语，欢迎免费使用。",{"type":20,"tag":171,"props":480,"children":481},{},[482],{"type":26,"value":175},{"title":7,"searchDepth":177,"depth":177,"links":484},[485,486,487,488,489],{"id":394,"depth":177,"text":394},{"id":404,"depth":177,"text":404},{"id":56,"depth":177,"text":56},{"id":136,"depth":177,"text":136},{"id":162,"depth":177,"text":162},"content:blog:json-deserialization.md","blog/json-deserialization.md","blog/json-deserialization",{"_path":494,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":495,"description":496,"date":10,"category":11,"keywords":497,"body":501,"_type":184,"_id":649,"_source":186,"_file":650,"_stem":651,"_extension":189},"/blog/json-patch","JSON Patch 操作详解","JSON Patch (RFC 6902) 用一组操作描述 JSON 变更，支持 add/remove/replace/move/copy/test。",[498,499,500],"json patch","rfc 6902","json变更",{"type":17,"children":502,"toc":642},[503,508,513,518,523,528,533,537,607,611,629,633,638],{"type":20,"tag":21,"props":504,"children":506},{"id":505},"json-patch-操作详解",[507],{"type":26,"value":495},{"type":20,"tag":28,"props":509,"children":510},{},[511],{"type":26,"value":512},"JSON Patch 是 RFC 6902 定义的用操作数组描述 JSON 变更的格式，常用于增量更新与协同。",{"type":20,"tag":34,"props":514,"children":516},{"id":515},"操作类型",[517],{"type":26,"value":515},{"type":20,"tag":28,"props":519,"children":520},{},[521],{"type":26,"value":522},"add 添加、remove 删除、replace 替换、move 移动、copy 复制、test 测试。",{"type":20,"tag":34,"props":524,"children":526},{"id":525},"使用场景",[527],{"type":26,"value":525},{"type":20,"tag":28,"props":529,"children":530},{},[531],{"type":26,"value":532},"API 增量更新、协同编辑、版本差异表达。",{"type":20,"tag":34,"props":534,"children":535},{"id":56},[536],{"type":26,"value":56},{"type":20,"tag":60,"props":538,"children":540},{"className":62,"code":539,"language":64,"meta":7,"style":7},"[{\"op\":\"replace\",\"path\":\"/name\",\"value\":\"新值\"}]\n",[541],{"type":20,"tag":67,"props":542,"children":543},{"__ignoreMap":7},[544],{"type":20,"tag":71,"props":545,"children":546},{"class":73,"line":74},[547,552,557,561,566,570,575,579,584,588,593,597,602],{"type":20,"tag":71,"props":548,"children":549},{"style":78},[550],{"type":26,"value":551},"[{",{"type":20,"tag":71,"props":553,"children":554},{"style":95},[555],{"type":26,"value":556},"\"op\"",{"type":20,"tag":71,"props":558,"children":559},{"style":78},[560],{"type":26,"value":92},{"type":20,"tag":71,"props":562,"children":563},{"style":272},[564],{"type":26,"value":565},"\"replace\"",{"type":20,"tag":71,"props":567,"children":568},{"style":78},[569],{"type":26,"value":123},{"type":20,"tag":71,"props":571,"children":572},{"style":95},[573],{"type":26,"value":574},"\"path\"",{"type":20,"tag":71,"props":576,"children":577},{"style":78},[578],{"type":26,"value":92},{"type":20,"tag":71,"props":580,"children":581},{"style":272},[582],{"type":26,"value":583},"\"/name\"",{"type":20,"tag":71,"props":585,"children":586},{"style":78},[587],{"type":26,"value":123},{"type":20,"tag":71,"props":589,"children":590},{"style":95},[591],{"type":26,"value":592},"\"value\"",{"type":20,"tag":71,"props":594,"children":595},{"style":78},[596],{"type":26,"value":92},{"type":20,"tag":71,"props":598,"children":599},{"style":272},[600],{"type":26,"value":601},"\"新值\"",{"type":20,"tag":71,"props":603,"children":604},{"style":78},[605],{"type":26,"value":606},"}]\n",{"type":20,"tag":34,"props":608,"children":609},{"id":136},[610],{"type":26,"value":136},{"type":20,"tag":140,"props":612,"children":613},{},[614,622],{"type":20,"tag":144,"props":615,"children":616},{},[617],{"type":20,"tag":87,"props":618,"children":620},{"href":619},"/diff",[621],{"type":26,"value":619},{"type":20,"tag":144,"props":623,"children":624},{},[625],{"type":20,"tag":87,"props":626,"children":627},{"href":149},[628],{"type":26,"value":149},{"type":20,"tag":34,"props":630,"children":631},{"id":162},[632],{"type":26,"value":162},{"type":20,"tag":28,"props":634,"children":635},{},[636],{"type":26,"value":637},"JSON Patch (RFC 6902) 用一组操作描述 JSON 变更，支持 add/remove/replace/move/copy/test。 JSONDog 提供全套 JSON 在线工具，纯前端、零上传、中英双语，欢迎免费使用。",{"type":20,"tag":171,"props":639,"children":640},{},[641],{"type":26,"value":175},{"title":7,"searchDepth":177,"depth":177,"links":643},[644,645,646,647,648],{"id":515,"depth":177,"text":515},{"id":525,"depth":177,"text":525},{"id":56,"depth":177,"text":56},{"id":136,"depth":177,"text":136},{"id":162,"depth":177,"text":162},"content:blog:json-patch.md","blog/json-patch.md","blog/json-patch",{"_path":653,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":654,"description":655,"date":10,"category":11,"keywords":656,"body":660,"_type":184,"_id":771,"_source":186,"_file":772,"_stem":773,"_extension":189},"/blog/json-performance","JSON 性能优化技巧","大 JSON 解析与传输优化：压缩、流式解析、字段裁剪、二进制替代方案。",[657,658,659],"json性能","json优化","大json",{"type":17,"children":661,"toc":764},[662,667,672,677,682,687,692,696,729,733,751,755,760],{"type":20,"tag":21,"props":663,"children":665},{"id":664},"json-性能优化技巧",[666],{"type":26,"value":654},{"type":20,"tag":28,"props":668,"children":669},{},[670],{"type":26,"value":671},"大 JSON 的解析与传输可能成为性能瓶颈，可通过多种手段优化。",{"type":20,"tag":34,"props":673,"children":675},{"id":674},"优化手段",[676],{"type":26,"value":674},{"type":20,"tag":28,"props":678,"children":679},{},[680],{"type":26,"value":681},"传输前 minify、gzip 压缩、流式解析（SAX）、按需裁剪字段、考虑 Protobuf/MessagePack。",{"type":20,"tag":34,"props":683,"children":685},{"id":684},"解析优化",[686],{"type":26,"value":684},{"type":20,"tag":28,"props":688,"children":689},{},[690],{"type":26,"value":691},"选用高性能库（如 simdjson）、Web Worker 避免阻塞主线程。",{"type":20,"tag":34,"props":693,"children":694},{"id":56},[695],{"type":26,"value":56},{"type":20,"tag":60,"props":697,"children":699},{"className":62,"code":698,"language":64,"meta":7,"style":7},"{\"big\": \"data...\"}\n",[700],{"type":20,"tag":67,"props":701,"children":702},{"__ignoreMap":7},[703],{"type":20,"tag":71,"props":704,"children":705},{"class":73,"line":74},[706,710,715,719,724],{"type":20,"tag":71,"props":707,"children":708},{"style":78},[709],{"type":26,"value":249},{"type":20,"tag":71,"props":711,"children":712},{"style":95},[713],{"type":26,"value":714},"\"big\"",{"type":20,"tag":71,"props":716,"children":717},{"style":78},[718],{"type":26,"value":269},{"type":20,"tag":71,"props":720,"children":721},{"style":272},[722],{"type":26,"value":723},"\"data...\"",{"type":20,"tag":71,"props":725,"children":726},{"style":78},[727],{"type":26,"value":728},"}\n",{"type":20,"tag":34,"props":730,"children":731},{"id":136},[732],{"type":26,"value":136},{"type":20,"tag":140,"props":734,"children":735},{},[736,743],{"type":20,"tag":144,"props":737,"children":738},{},[739],{"type":20,"tag":87,"props":740,"children":741},{"href":157},[742],{"type":26,"value":157},{"type":20,"tag":144,"props":744,"children":745},{},[746],{"type":20,"tag":87,"props":747,"children":749},{"href":748},"/visualize",[750],{"type":26,"value":748},{"type":20,"tag":34,"props":752,"children":753},{"id":162},[754],{"type":26,"value":162},{"type":20,"tag":28,"props":756,"children":757},{},[758],{"type":26,"value":759},"大 JSON 解析与传输优化：压缩、流式解析、字段裁剪、二进制替代方案。 JSONDog 提供全套 JSON 在线工具，纯前端、零上传、中英双语，欢迎免费使用。",{"type":20,"tag":171,"props":761,"children":762},{},[763],{"type":26,"value":175},{"title":7,"searchDepth":177,"depth":177,"links":765},[766,767,768,769,770],{"id":674,"depth":177,"text":674},{"id":684,"depth":177,"text":684},{"id":56,"depth":177,"text":56},{"id":136,"depth":177,"text":136},{"id":162,"depth":177,"text":162},"content:blog:json-performance.md","blog/json-performance.md","blog/json-performance",1787305467155]