Skip to content

Commit

Permalink
Released version 3.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Aug 1, 2014
1 parent fb16ec4 commit 4d58258
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsoneditor",
"version": "3.2.0-SNAPSHOT",
"version": "3.1.1",
"description": "A web-based tool to view, edit and format JSON",
"tags": [
"json",
Expand Down
58 changes: 55 additions & 3 deletions jsoneditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
* Copyright (c) 2011-2014 Jos de Jong, http://jsoneditoronline.org
*
* @author Jos de Jong, <[email protected]>
* @version 3.2.0-SNAPSHOT
* @date 2014-07-28
* @version 3.1.1
* @date 2014-08-01
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
Expand Down Expand Up @@ -1372,6 +1372,7 @@ return /******/ (function(modules) { // webpackBootstrap
* Parse JSON using the parser built-in in the browser.
* On exception, the jsonString is validated and a detailed error is thrown.
* @param {String} jsonString
* @return {JSON} json
*/
util.parse = function parse(jsonString) {
try {
Expand All @@ -1380,7 +1381,7 @@ return /******/ (function(modules) { // webpackBootstrap
catch (err) {
// try to load as JavaScript instead of JSON (like "{a: 2}" instead of "{"a": 2}"
try {
return eval('(' + jsonString + ')');
return util.parseJS(jsonString);
}
catch(err2) {
// ok no luck loading as JavaScript
Expand All @@ -1394,6 +1395,57 @@ return /******/ (function(modules) { // webpackBootstrap
}
};

/**
* Parse a string containing an object in JavaScript notation into a JSON.
* Throws an error when not successful. This function can for example parse
* a string like "{a: 2, 'b': {c: 'd'}".
* @param {string} jsString
* @returns {JSON} json
*/
util.parseJS = function (jsString) {
// escape quotes inside strings
var chars = [];
var inString = false;
var i = 0;
while(i < jsString.length) {
var c = jsString.charAt(i);

if (c === '"' || c === '\'') {
if (c === inString) {
// end of string
inString = false;
}
else if (!inString) {
// start of string
inString = c;
}
else {
// add escape character if not escaped
if (jsString.charAt(i - 1) !== '\\') {
chars.push('\\');
}
}
}

chars.push(c);
i++;
}
var jsonString = chars.join('');

// replace keys/values enclosed by single quotes with double quotes
jsonString = jsonString.replace(/(.)'/g, function ($0, $1) {
var str = $1.replace(/"/g, '\\"'); // escape double quotes
return ($1 == '\\') ? '\'' : str + '"';
});

// enclose unquoted object keys with double quotes
jsonString = jsonString.replace(/([{,]\s*)([a-zA-Z_][a-zA-Z0-9_]*)(\s*:)/g, function ($0, $1, $2, $3) {
return $1 + '"' + $2 + '"' + $3;
});

return JSON.parse(jsonString);
};

/**
* Validate a string containing a JSON object
* This method uses JSONLint to validate the String. If JSONLint is not
Expand Down
2 changes: 1 addition & 1 deletion jsoneditor.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions jsoneditor.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsoneditor",
"version": "3.2.0-SNAPSHOT",
"version": "3.1.1",
"main": "jsoneditor.js",
"description": "A web-based tool to view, edit and format JSON",
"tags": [
Expand Down

0 comments on commit 4d58258

Please sign in to comment.