You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS 2022 JSON数组格式化:如何移除数组括号内的空格?

解决Visual Studio 2022无扩展时JSON数组括号内空格的.editorconfig配置方案

在无扩展的Visual Studio 2022中,JSON文件格式化后数组的方括号内侧会自动添加空格,示例如下:

{
  "key": [ "val1","val2","val3" ]
}

期望的格式是数组首尾方括号内侧无空格:

{
  "key": ["val1","val2","val3"]
}

你之前尝试的.editorconfig配置无效,是因为使用了错误的属性名。Visual Studio 2022的内置JSON格式化器需要使用带json.前缀的专属配置项,正确的配置如下:

[*.json]
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
json.array_bracket_spacing = false

json.array_bracket_spacing属性专门控制JSON数组方括号与元素之间的空格,设置为false即可移除[后和]前的多余空格,达到你想要的格式化效果。

内容的提问来源于stack exchange,提问作者Metro Smurf

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 07:22:05