Skip to content

kazakh87/smallJSON

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

smallJSON

Reduce JSON by not nessesery whitespaces. It use ECMA-262 3rd Edition as JSON base and removes space, linefeed, carriage rerun or horizontal tab as whitespaces.

var smallJSON = function (json) {
  if (typeof json == "string") {
      return json.trimEnd().replace(/ (?=(?:(?:\\.|[^\\"])*"(?:\\.|[^\\"])*")*(?:\\.|[^\\"])*\})|[\n\r\t\v]*/g, "");
    } else {
      return json;
    }
};

var test_json = "{ \"key\": \"value\" }";
alert(smallJSON(test_json));

Thanks to Tim Pietzcker for regex exempla with groups.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors