如何在 Visual Studio Code 中水平显示数字 json 数组?

gea*_*ear 3 visual-studio-code

当我在 Visual Studio Code 中保存 json 文件后,它会自动格式化文档,数组会垂直显示(通过添加换行符)。由于我有巨大的整数数组,因此几乎不可能快速查看文件。例子:

{
    "big_integer_array": [
        12,
        15,
        13,
        1,
        5,
        8,
        15,
        14,
        12,
        ...
    ],
    "this_value_is_in_line_million": true
}
Run Code Online (Sandbox Code Playgroud)

我如何告诉程序,像这样水平显示数字数组:

{
    "big_integer_array": [12,15,13,1,5,8,15,14,12, ...],
    "this_value_is_in_line_three": true
}
Run Code Online (Sandbox Code Playgroud)

解决方案

  1. 使用扩展 esbenp.prettier-vscode
  2. 将 prettier.printwidth 设置为 99999999999

在此输入图像描述

Mar*_*ark 7

vscode v1.70 内置了一个专门针对这种情况的新设置:

JSON > Format: Keep Lines  <= enable this in your Settings
"json.format.keepLines": true <= or use that setting in your settings.json
Run Code Online (Sandbox Code Playgroud)

此功能允许在 JSON 文档的行格式化时保留初始行位置。例如,在一行上包含值的数组在格式化后仍将在同一行上包含这些值。JSON > Format: Keep Lines要启用此功能,请在设置中启用该选项。

使用 Insiders Build 进行演示 - 首先不启用设置,然后启用设置后:

JSON 格式化保留行演示