This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/layers/+lang/json
syl20bnr 584392bd92 [core] Fix layer dependencies based on layer variables
There was a edge case with the declaration of the `lsp` layer in `layers.el`
files.
The `hy` layer depends on the `python` layer which in turn depends on the `lsp`
layer if and only if the `python-backend` layer variable is set to `lsp`.
When the `hy` layer was declared first then it declares the `python` layer
without its layer variables, thus the `lsp` layer was not declared because the
`python-backend` variable was not set.

The fix is to gather all the layer dependencies and resolve them only after all
the used layers have been declared.

* new function `configuration-layer/declare-layer-dependencies`
* replace all calls to `configuration-layer/declare-layer` by the new function
  except for distribution layers (we declare layer dependencies right away in
  distribution layers)
2019-09-30 02:00:48 -04:00
..
img Create new json layer extracted from javascript layer 2018-05-14 00:49:13 -04:00
config.el [json] Add option to format on save 2019-09-05 18:58:08 +02:00
funcs.el json: tell prettier content is to be parsed as json 2018-11-07 08:27:47 +02:00
layers.el [core] Fix layer dependencies based on layer variables 2019-09-30 02:00:48 -04:00
packages.el [json] Add option to format on save 2019-09-05 18:58:08 +02:00
README.org documentation formatting: Thu Sep 5 19:09:25 UTC 2019 2019-09-05 21:24:39 +02:00

JSON layer

/TakeV/spacemacs/media/commit/1de8157a5cd4e2acd4798b15995a18bbb90eb95b/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.

Formatting on save

To enable using the selected formatter on save, set the layer variable json-fmt-on-save:

  (json :variables json-fmt-on-save t)

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