Fixed #111: accept JavaScript objects as input, and turn them into valid JSON

This commit is contained in:
jos 2014-07-26 15:01:53 +02:00
parent bb53153d3b
commit c72ea9b6e1
8 changed files with 54 additions and 28 deletions

View File

@ -3,6 +3,12 @@
https://github.com/josdejong/jsoneditor
## not yet released, version 3.1.0
- JSONEditor now accepts JavaScript objects as input, and can turn them into
valid JSON. For example `{a:2,b:'str'}` can be turned into `{"a":2,"b":"str"}`.
## 2014-05-31, version 3.0.0
- Large code reorganization.

View File

@ -1,6 +1,6 @@
{
"name": "jsoneditor",
"version": "3.0.0",
"version": "3.1.0-SNAPSHOT",
"description": "A web-based tool to view, edit and format JSON",
"tags": [
"json",

View File

@ -23,8 +23,8 @@
* Copyright (c) 2011-2014 Jos de Jong, http://jsoneditoronline.org
*
* @author Jos de Jong, <wjosdejong@gmail.com>
* @version 3.0.0
* @date 2014-05-31
* @version 3.1.0-SNAPSHOT
* @date 2014-07-26
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
@ -37,44 +37,43 @@
root["JSONEditor"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
@ -1386,9 +1385,19 @@ return /******/ (function(modules) { // webpackBootstrap
return JSON.parse(jsonString);
}
catch (err) {
// try to throw a more detailed error message using validate
util.validate(jsonString);
throw err;
// try to load as JavaScript instead of JSON (like "{a: 2}" instead of "{"a": 2}"
try {
return eval('(' + jsonString + ')');
}
catch(err2) {
// ok no luck loading as JavaScript
// try to throw a more detailed error message using validate
util.validate(jsonString);
// rethrow the original error
throw err;
}
}
};

File diff suppressed because one or more lines are too long

2
jsoneditor.min.css vendored

File diff suppressed because one or more lines are too long

9
jsoneditor.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "jsoneditor",
"version": "3.0.0",
"version": "3.1.0-SNAPSHOT",
"main": "jsoneditor.js",
"description": "A web-based tool to view, edit and format JSON",
"tags": [

View File

@ -13,9 +13,19 @@ define(function () {
return JSON.parse(jsonString);
}
catch (err) {
// try to throw a more detailed error message using validate
util.validate(jsonString);
throw err;
// try to load as JavaScript instead of JSON (like "{a: 2}" instead of "{"a": 2}"
try {
return eval('(' + jsonString + ')');
}
catch(err2) {
// ok no luck loading as JavaScript
// try to throw a more detailed error message using validate
util.validate(jsonString);
// rethrow the original error
throw err;
}
}
};