From bcdd329e87b26b47ec63ccfdb8e1c8457c66bd02 Mon Sep 17 00:00:00 2001 From: Romain Schmitz Date: Sun, 20 Apr 2014 12:54:56 +0200 Subject: [PATCH] Check if the text is a json and prettify it --- src/ui-ace.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ui-ace.js b/src/ui-ace.js index 053c30e..68b5b17 100644 --- a/src/ui-ace.js +++ b/src/ui-ace.js @@ -220,7 +220,17 @@ angular.module('ui.ace', []) }); ngModel.$render = function () { - session.setValue(ngModel.$viewValue); + var text = ngModel.$viewValue; + + try { + // check if the text is a json and prettify it + var obj = JSON.parse(text); + text = JSON.stringify(obj, null, '\t'); + } catch(e) { + + } + + session.setValue(text); }; }