Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove empty objects, as well as keep 0 and false with remove_empty_properties #736

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

thatnerdjosh
Copy link

No description provided.

@@ -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];
Copy link

@dexif dexif Apr 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong logic. It's should be...
Oh... And you should check if result[i] == null

if(typeof result[i] === 'undefined' || result[i] === '' || (result[i] !== null && Object.keys(result[i]).length == 0 && result[i].constructor == Object)) delete result[i];

btsimonh pushed a commit to btsimonh/json-editor that referenced this pull request May 26, 2021
btsimonh pushed a commit to btsimonh/json-editor that referenced this pull request May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants