From 6902d93cc12c5ca46cf485138bd0b8917c3733e6 Mon Sep 17 00:00:00 2001 From: Andrea Di Toro Date: Thu, 6 Apr 2017 16:12:11 +0200 Subject: [PATCH] remove empty object --- src/editors/object.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/editors/object.js b/src/editors/object.js index cdfae3908..78002451e 100644 --- a/src/editors/object.js +++ b/src/editors/object.js @@ -777,6 +777,23 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({ } } + if(this.jsoneditor.options.remove_empty_object || this.options.remove_empty_object) { + for(var k in result) { + if(result[k] instanceof Object){ + var keys = Object.keys(result[k]) + var ignore = this.editors[k].schema.options.remove_empty_object_ignore + if(ignore){ + keys = keys.filter(function(value){ + return !ignore.includes(value); + }); + } + if(!keys.length){ + delete result[k]; + } + } + } + } + return result; }, refreshValue: function() {