1

Emacs 26.1. Windows 10

It's has function json-pretty-print . But it not enough for me. Has any another better json formater and validator? I mean the next.

Suppose I has error on json on line 26. I missed ",". But json-pretty-print get me strange error message:

Json readtable error: 93

enter image description here

I don't understand this message. What does it mean? Why simple not get message something like this:

Error: Parse error on line 26:
...n1_FR"           }       ]   }   "loyalty": true,    "u
-------------------^
Expecting 'EOF', '}', ',', ']', got 'STRING'

So that is the reason why I need better json validator and formater.

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

  • I update my post with explain what I mean "good". – Alexei Nov 17 '18 at 13:06
0

I'm really curious about why you feel json-pretty-print is not good enough.

Perhaps you don't like needing to call it manually? You could set it to run whenever you save the file:

(add-hook
 'json-mode-hook
 (lambda ()
   (add-hook 'before-save-hook 'json-pretty-print-buffer t t)))

If you'd still like an alternative, I highly recommend prettier-mode. It's a minor mode that runs the file through prettier on save. In circumstances with invalid JSON it does give you diagnostic output (but does not enforce strict JSON AFAIK. For example:

prettier errors:
[error] stdin: SyntaxError: Unexpected token, expected "," (4:7)
[error]   2 |   "foo": {
[error]   3 |       "bar": "baz"
[error] > 4 |       "blah": "blooh"
[error]     |       ^
[error]   5 |   }
[error]   6 | }
[error]   7 | 
  • I updated my post. – Alexei Nov 17 '18 at 13:07
  • I install prettier-mode. How I can validate json? What is the command for this? – Alexei Nov 18 '18 at 10:47
  • Emacs 26.1, Windows 10. – Alexei Nov 18 '18 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.