VSCode JSON 格式化器:不要包装 JSON 对象

5

我现在正在使用avro .avsc模式,我喜欢样例的格式:

{
 "namespace": "example.avro",
 "type": "record",
 "name": "User",
 "fields": [
     {"name": "name", "type": "string"},
     {"name": "favorite_number",  "type": ["int", "null"]},
     {"name": "favorite_color", "type": ["string", "null"]}
 ]
}

我是指一行字段定义,特别是{"name": "name", "type": "string"}

我想在 VSCode 中编辑和格式化我的模式,但它会将字段包装成多行:

 {
   "name": "name",
   "type": "string"
 }

我尝试在setting.json中配置默认的JSON格式化程序,并使用beautify扩展,但没有成功。

   "[json]": {
        "editor.tabSize": 2,
        "editor.wordWrap": "off",
        "editor.defaultFormatter": "vscode.json-language-features",
        // "editor.defaultFormatter": "HookyQR.beautify"
    },
    "html.format.wrapAttributes": "preserve",

    "beautify.config": {
        "indent_size": 2,
        "indent_char": " ",
        "preserve_newlines": true,
        "space_in_paren": true,
        "space_in_empty_paren": true,
        "wrap_attributes": "preserve", 
    },

1
请参考 https://dev59.com/OHIOtIcB2Jgan1znHEnO#73180702 - 新增了一个设置,可以让信息保持在您想要的同一行。 - Mark
1个回答

3
FracturedJson VSCode扩展可能对您有用。(我是作者。 它是在MIT许可下的开源软件。)基本思想是对象和数组写在单行上,只要它们不太长且嵌套不太深即可。如果您想在下载扩展之前尝试一下其功能,请使用浏览器版本

啊,糟糕。我本来还抱有希望,觉得这个可能是“适合我的”,但看起来它好像不处理注释。 :( - MostHated
经过一些设置的调整,我成功地将600万行JSON格式化并批量导入到ElasticSearch中。非常感谢! - James Hooper

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接