jbuilder
jbuilder copied to clipboard
Ignore! block
Just like ignore_nil! , can we have ignore! method which takes in a block.
This can be useful if we don't want (empty strings, empty array, etc) in our JSON output. I think the block will be really useful.
What are your thoughts on this. If it seems like a good idea, I can start working on this.
@rwz what do you think about this?
I noticed that null within objects which are within an array don't get removed.
@aubergene
return if @ignore_nil && value.nil? or _blank?(value)link
According to this line, only nil values will be ignored which are the topmost level.
json.ignore_nil! json.set 'this_hash' {'a' => nil}
will output json with this_hash key with a inside it.
I think this is the intended behaviour here.
However I am suggesting we give the user the power to ignore value according to their condition which can be given in a block.
You're right this is different issue. I opened #363 with a test to demonstrate.
nil values are ignored within nested objects, I think it's a different issue.
json.ignore_nil! true
json.one do
json.name "Bob"
json.dne nil
json.two do
json.name "Bob 2"
json.dne nil
end
end