AnswerBun.com

Where find good json formater and validation?

Emacs Asked by a_subscriber on December 17, 2020

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.

One Answer

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 | 

Answered by ebpa on December 17, 2020

Add your own answers!

Related Questions

Replace welcome screen (aka “splash” screen) with calendar?

3  Asked on December 19, 2021 by philip-kirkbride

   

Hook with quoted lambda as an argument

1  Asked on December 19, 2021 by siery

     

compilation-mode and next-error confusion

2  Asked on December 16, 2021 by kpixley

 

Font and frame configuration in daemon mode

2  Asked on December 11, 2021 by thomas-kahle

     

Colored string in mode line

2  Asked on December 11, 2021

       

Helm: helm-find-files: how find files recursive?

3  Asked on December 9, 2021 by user8542613

   

How can I start learning Emacs Lisp?

9  Asked on December 9, 2021 by user1172468

   

It is safe to delete set free variables?

0  Asked on December 9, 2021

 

Using openwith (or alternative) on Mac

1  Asked on December 9, 2021

 

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP