Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>JSON to Go StructNew to Visual Studio Code? Get it now.
JSON to Go Struct

JSON to Go Struct

chenyihui

|
2 installs
| (0) | Free
Convert JSON to Go struct with JSON tags
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

JSON to Go Struct for VS Code

此插件可以将 JSON 字符串自动转换为带有 JSON tag 的 Go 结构体。

功能特性

  • 自动粘贴(New!):在 Go 文件中直接粘贴 JSON (Ctrl+V / Cmd+V),自动转换为 Go 结构体。
  • 自动类型推断:支持 string, int, float64, bool, struct, slice 等类型。
  • 自动生成 JSON Tag:生成的结构体字段自动带有 json:"key" tag。
  • 智能命名:自动将 JSON 字段名转换为 PascalCase 的 Go 导出字段名。
  • 支持嵌套结构:自动处理嵌套的对象和数组。
  • 支持剪贴板:如果没有选中文本,自动读取剪贴板中的 JSON 进行转换。

使用方法

自动转换(推荐)

  1. 复制一段 JSON 文本。
  2. 打开一个 Go 文件 (.go)。
  3. 按 Ctrl+V (Mac: Cmd+V) 粘贴。
  4. 插件会自动检测并转换 JSON 为 Go 结构体。如果剪贴板内容不是 JSON,则执行普通粘贴。

手动转换

  1. 复制一段 JSON 文本。
  2. 打开一个 Go 文件。
  3. 按 Ctrl+Alt+V (Mac: Cmd+Alt+V)。
  4. 或者右键菜单选择 "Convert JSON to Go Struct"。
  5. 或者使用命令面板 (Ctrl+Shift+P / Cmd+Shift+P) 输入 "Convert JSON to Go Struct"。

安装开发

  1. 安装依赖:
    npm install
    
  2. 编译:
    npm run compile
    
  3. 按 F5 启动调试。

测试

运行单元测试:

npx mocha --ui tdd out/test/suite/json2go.test.js
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft