Sublime Forum

How to prevent automatic prettifying of JSON on save?

#1

I don’t ever recall installing a JSON-related package, but currently ST3 prettifies my JSON on save, which wouldn’t be so bad except that it uses a format I don’t like. Specifically, ST3 likes to save JSON like this…

"a": [{
    "b": {
        "c": "d"
    },
    "e": {
        "f": "g"
    }
}, {
    "b": {
        "c": "d"
    },
    "e": {
        "f": "g"
    }
}, {
    "b": {
        "c": "d"
    },
    "e": {
        "f": "g"
    }
}]}

…whereas I prefer this…

"a": [
    {
        "b": {
            "c": "d"
        },
        "e": {
            "f": "g"
        }
    },
    {
        "b": {
            "c": "d"
        },
        "e": {
            "f": "g"
        }
    }, 
    {
        "b": {
            "c": "d"
        },
        "e": {
            "f": "g"
        }
    }
]

…where each array element uses its own set of lines, which makes for slightly easier insertions and deletions.

In fact, there is currently a “fight” going on between one of my programs (KarabinerElements) and ST3, in that KE saves the json one way (the way I like it), and ST3 saves it another way (that I don’t like).

Anyway, all this to say that I’m trying to stop ST3 from autoformatting-on-save my poor JSON. I couldn’t find settings that seem to relate to JSON, nor an obvious culprit package. Here is my list of active packages (those that show up when I do Disable Package):

  • ActionScript
  • Anaconda
  • AppleScript
  • ASP
  • Batch File
  • C#
  • C++
  • Clojure
  • Color Scheme - Default
  • Color Scheme - Legacy
  • CSS
  • D
  • Diff
  • Elixir
  • ElixirFormatter
  • Emmet
  • Erlang
  • Extract Sublime Package
  • File Rename
  • Git Formats
  • Go
  • GraphViz
  • Groovy
  • Haskell
  • HexViewer
  • HTML
  • Indent XML
  • Java
  • JavaScript
  • JsFormat
  • Language English
  • LaTeX
  • LESS
  • Lisp
  • Lua
  • Makefile
  • Markdown
  • Matlab
  • Objective-C
  • OCaml
  • Package Control
  • Package Resource Viewer
  • Pascal
  • Perl
  • PHP
  • Python
  • PyV8
  • R
  • Rails
  • RawLineEdit
  • Regular Expressions
  • Restructured Text
  • Ruby
  • Rust
  • Sass
  • Scala
  • SelectUntil
  • ShellScript
  • SQL
  • SublimeREPL
  • TCL
  • Text
  • Textile
  • Theme - Default
  • Theme - Flatland
  • Theme - Soda
  • TypeScript Syntax
  • WordCount
  • XML
  • YAML

(Yes I did type that all by hand.)

Thanks!

0 Likes

#2

Just at a glance it feels like a package named JsFormat would format JS and possibly also JSON.

0 Likes

#3

Well, silly me, that was it.

I could disable it in that package settings.

(In passing, please someone let me know if there is a json formatter that can format as in the preferred option above.)

0 Likes

#4

https://packagecontrol.io/packages/IndentX

0 Likes

#5

Well… IndentX seems to format JSON as in my non-preferred option (same as JSFormat). Am I missing an option somewhere?

0 Likes