var q; if (document.selection.text) { try { q = JSON.parse(document.selection.Text); document.selection.text = JSON.stringify(q, undefined, 2); } catch (err) { Window.OutputBar.writeln("Selected text couldnt have been formatted as json. Most likely it's not json: " + err.message + " " + err.fileName + ":" + err.lineNumber); Window.OutputBar.Visible = true; } } else { // alert('There is no selection'); // Window.prompt('There is no selection provided'); Window.OutputBar.writeln('There is no selection provided. Please select text to formt it as json'); Window.OutputBar.Visible = true; }