From d0d2a2c61334e0f4208c79eaa28f69208bfb4b11 Mon Sep 17 00:00:00 2001 From: Dexif Date: Fri, 24 Feb 2017 16:57:56 +0300 Subject: [PATCH 1/2] fix for sending 0 and false with remove_empty_properties=true --- src/editors/number.js | 2 +- src/editors/object.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/editors/number.js b/src/editors/number.js index acc65ee4d..a1def6799 100644 --- a/src/editors/number.js +++ b/src/editors/number.js @@ -6,6 +6,6 @@ JSONEditor.defaults.editors.number = JSONEditor.defaults.editors.string.extend({ return 2; }, getValue: function() { - return this.value*1; + return this.value===''?undefined:this.value*1; } }); diff --git a/src/editors/object.js b/src/editors/object.js index 22410db84..6940ba9b5 100644 --- a/src/editors/object.js +++ b/src/editors/object.js @@ -698,7 +698,7 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({ if(this.jsoneditor.options.remove_empty_properties || this.options.remove_empty_properties) { for(var i in result) { if(result.hasOwnProperty(i)) { - if(!result[i]) delete result[i]; + if(typeof result[i] === 'undefined' || result[i] === '') delete result[i]; } } } @@ -712,7 +712,7 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({ if(!this.editors.hasOwnProperty(i)) continue; this.value[i] = this.editors[i].getValue(); } - + if(this.adding_property) this.refreshAddProperties(); }, refreshAddProperties: function() { From 957b1c1b6d8765b47a2d1501aecc7c903c0a22ed Mon Sep 17 00:00:00 2001 From: Josh Santos Date: Wed, 8 Mar 2017 12:37:14 -0800 Subject: [PATCH 2/2] Add empty object deletion --- src/editors/object.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/editors/object.js b/src/editors/object.js index 6940ba9b5..4b34ba484 100644 --- a/src/editors/object.js +++ b/src/editors/object.js @@ -698,7 +698,7 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({ if(this.jsoneditor.options.remove_empty_properties || this.options.remove_empty_properties) { for(var i in result) { if(result.hasOwnProperty(i)) { - if(typeof result[i] === 'undefined' || result[i] === '') delete result[i]; + if(typeof result[i] === 'undefined' || result[i] === '' || Object.keys(result[i]).length == 0 && result[i].constructor == Object) delete result[i]; } } }