Skip to content

Commit

Permalink
native JSON support is added
Browse files Browse the repository at this point in the history
  • Loading branch information
vkiryukhin committed Jun 14, 2012
1 parent 1ed2b70 commit fbea9e5
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion vkbeautify.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* vkBeautify - javascript plugin to pretty-print or minify text in XML, JSON and CSS formats.
*
* Version - 0.97.00.beta
* Version - 0.98.00.beta
* Copyright (c) 2012 Vadim Kiryukhin
* vkiryukhin @ gmail.com
* http://www.eslinstructor.net/vkbeautify/
Expand Down Expand Up @@ -152,6 +152,21 @@ vkbeautify.prototype.xml = function(text,step) {

vkbeautify.prototype.json = function(text,step) {

// Attempt to process using the native JSON first
if ( window.JSON && window.JSON.stringify ) {
if ( typeof text === "string" ) {
return JSON.stringify(JSON.parse(text), null, step);
}
if ( typeof text === "object" ) {
return JSON.stringify(text, null, step);
}
return null;
}

// there is no native JSON object, so let's use regexp

if ( typeof text !== "string" || !text ) return null;

var ar = this.jsonmin(text).replace(/\{/g,"~::~{~::~")
.replace(/\[/g,"[~::~")
.replace(/\}/g,"~::~}")
Expand Down

0 comments on commit fbea9e5

Please sign in to comment.