format json

809 views
Skip to first unread message

sym3tri

unread,
May 16, 2012, 6:58:35 PM5/16/12
to ace-d...@googlegroups.com
Does functionality exist to format JSON conent?
I didn't see anything in the API docs.

I'm looking for a function like...

editor.format()
or
editor.formatJson()

or something similar.
thanks.

Harutyun Amirjanyan

unread,
May 17, 2012, 2:56:36 AM5/17/12
to ace-d...@googlegroups.com
no
but if you need it only for valid json you can just do
JSON.stringify(JSON.parse(str), null, 4)
for formatting broken json or js use jsBeautify instead
(https://github.com/einars/js-beautify it even works for html and css)
see https://github.com/MikeRatcliffe/Acebug/blob/master/chrome/content/ace++/startup.js#L369-414
for an example

sym3tri

unread,
May 17, 2012, 5:26:52 PM5/17/12
to ace-d...@googlegroups.com
Awesome. Thanks! 
I never noticed the extra optional arguments in JSON.stringify.
Reply all
Reply to author
Forward
0 new messages