# To\_xml and to\_json behaviour with nil values

**URL:** <https://www.ruby-forum.com/t/to-xml-and-to-json-behaviour-with-nil-values/144716>\
**Category:** Rails\
**Created:** [August 1, 2008, 2:05pm UTC](https://www.ruby-forum.com/t/to-xml-and-to-json-behaviour-with-nil-values/144716 "2008-08-01T14:05:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 1, 2008, 2:05pm UTC](https://www.ruby-forum.com/t/to-xml-and-to-json-behaviour-with-nil-values/144716/1 "2008-08-01T14:05:14Z")

</div>

Hi,

i was wondering if there is any way to just skip attributes having nil  
values when to\_xml or to\_json on ActiveRecord.  
The default behavior is to include a nil value:  
xml:  
  
json:  
“identity\_url”: null

Is there an option way to make this value just not appear ? Or should  
it be a hack in the serialization itself ?  
Thank you,

Elise
