Question

I've got some JSON data, but it's all on one line. Does anyone know of a web or Windows editor that will format (e.g. indent and insert new lines) this data for me, so I can read it better? Preferably one that uses a GUI to display the JSON—instead of a command-line tool that outputs a reformatted document, for example.

Was it helpful?

Solution

Have you tried this?

http://jsonformat.com/

OTHER TIPS

I have recently created JSON Editor Online, a tool to easily edit and format JSON online. JSON is displayed in a clear, editable treeview and in formatted plain text.

http://jsoneditoronline.org/

You can download http://www.thomasfrank.se/json_editor.html and run it locally on your own data, although it is an editor rather than a formatter.

http://www.jsonlint.com/ is also a useful validation and reformatting tool.

On windows I go for: http://jsonviewer.codeplex.com/

Handy for pulling raw JSON responses from Firebug and parsing it for me.

I use http://curiousconcept.com/jsonformatter to format computer generated jsons. It makes it much readable.

Remember that JSON is just a Javascript Object Literal with fancy clothes. You should be able to use any Javascript Beautifier to clean it up.

I like this one here: http://freeformatter.com/json-formatter.html

The validation process is flexible if your doc does not adhere to the RFC standards. It also creates a tree with collapsible nodes which is cool when you want to work in a small area of the json tree

Here's what I do: use the Aptana Eclipse Javascript Editor, which will check your syntax as you type. There's only one trick: you have to wrap your json in a tiny bit of javascript to make the whole thing a valid javascript file, and eliminate those red and yellow syntax errors.

So, the outer-most {} becomes: x={}; ( with all your json stuff in the middle ).

Now you just have to strip-off the x= and the ; before parsing as JSON. I do this in a function that wraps the jQuery ajax function:

function get_json_file(url,options,callback){
    var opts = {dataType:"text"};
    opts.url = url;
    $.extend(opts,options);
    opts.success=function(data){
        var json = data.substring(data.indexOf('{'),data.lastIndexOf('}')+1);
        var obj = JSON.parse(json);
        callback(obj);
    };
    $.ajax(opts);
}

It's a bit crazy, but it's worth it to effectively have a really good syntax-checking JSON editor in eclipse.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top