spacemacs/layers/+lang/json
Seong Yong-ju 2c21d5098a Add prettier layer
Add prettier layer. Add prettier support for .css/.scss/.less/.js/.json file.
Add layer variables for html, javascript, json.
2018-08-22 00:15:28 +03:00
..
img Create new json layer extracted from javascript layer 2018-05-14 00:49:13 -04:00
config.el Add prettier layer 2018-08-22 00:15:28 +03:00
funcs.el Fix various typos 2018-05-23 22:12:30 -04:00
layers.el Add prettier layer 2018-08-22 00:15:28 +03:00
packages.el Add prettier layer 2018-08-22 00:15:28 +03:00
README.org Add prettier layer 2018-08-22 00:15:28 +03:00

JSON layer

/TakeV/spacemacs/media/commit/314e3470efcf7144f21d5347ab21849c1a6d1bbf/layers/+lang/json/img/json.png

Description

This layer adds support for JSON files with json-mode

Features:

Install

To use this configuration layer, add it to your ~/.spacemacs. You will need to add json to the existing dotspacemacs-configuration-layers list in this file.

Configuration

To define the default indentation set the variable js-indent-level.

web-beautify

See web-beautify layer documentation.

prettier

See prettier layer documentation.

Choosing a formatter

To choose a formatter, set the layer variable json-fmt-tool:

(json :variables json-fmt-tool 'web-beautify)

Formatter can be chosen on a per project basis using directory local variables (files named .dir-locals.el at the root of a project), an example to use the prettier formatter:

;;; Directory Local Variables
;;; For more information see (info "(emacs) Directory Variables")

((json-mode (json-fmt-tool . prettier)))

Note: you can easily add a directory local variable with SPC f v d.

Usage

Reformat

SPC m = will reformat the whole buffer or the active region. Use numerical prefix argument to specify a different indentation than js-indent-level. Use the universal prefix argument to print decoded strings, for instance:

{"name":"foo\"bar","nick":"foo \u00e4 bar","description":"<pre>\nbaz\n</pre>","home":"/home/foobar"}

Will be reformatted:

{
  "name": "foo\"bar",
  "nick": "foo ä bar",
  "description": "<pre>
  baz
  </pre>",
  "home": "/home/foobar"
}

Display navigable hierarchy

SPC m h h displays the hierarchy for the whole JSON document or the active region. Use the universal prefix argument SPC u SPC m h h to create the hierarchy for the JSON after the point.

Key Bindings

Key Binding Description
SPC m = DWIM Reformat JSON
SPC m h p Get the path of the value at point
SPC m h h DWIM navigate JSON hierarchy
SPC m h H Navigate JSON hierarchy of the whole buffer

JSON hierarchy

Key Binding Description
RET Expand/Collapse node
TAB Select next node
S-TAB Select previous node