jsonvisual-studio-codeformattingavsc

vscode json formatter: do not wrap json objects


I'm working with avro .avsc schemas now and I like formatting in samples:

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

I mean one-line field definitions {"name": "name", "type": "string"} specifically.

I'd like to edit and format my schemas in vscode, but it keeps wrapping fields like

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

I tried to configure default json formatter and with beautify extension in setting.json, but got no luck

   "[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", 
    },

Solution

  • The FracturedJson VSCode extension might be useful for you. (I'm the author. It's open source under the MIT license.)

    The basic idea is that objects and arrays are written on single lines, as long as they're not too long and not too deeply nested.

    There's a browser version if you'd like to play around with the capabilities before downloading the extension.