How can I set a tab width for JSON files?

emacs, indentation, json

Solution

(add-hook 'json-mode-hook
          (lambda ()
            (make-local-variable 'js-indent-level)
            (setq tab-width 2)
            (setq js-indent-level 2)))

Make the variable buffer local so that it does not conflict with `js-mode` for JavaScript files.

Problem

I have the following in my `.emacs` file. But it doesn't change the tab width in `.json` files. ``` (setq-default indent-tabs-mode nil) (setq-default tab-width 2) (setq standard-indent 2) ``` I'm using emacs 24.3 on OS X 10.8.4

Original source