# Another YAML bug?

**URL:** <https://www.ruby-forum.com/t/another-yaml-bug/76935>\
**Category:** Ruby\
**Created:** [November 22, 2006, 3:43pm UTC](https://www.ruby-forum.com/t/another-yaml-bug/76935 "2006-11-22T15:43:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![popolzen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@popolzen](https://www.ruby-forum.com/u/popolzen)\
**Post date:** [November 22, 2006, 3:43pm UTC](https://www.ruby-forum.com/t/another-yaml-bug/76935/1 "2006-11-22T15:43:46Z")

</div>

```auto
#!/usr/bin/ruby1.8
require 'yaml'
a = { "b" => "c", "d" => nil, "e" => "f" }
puts a.to_yaml
```

result:

* * *

b: c  
d:  
e: f

but must be:

* * *

b: c  
d: ~  
e: f

---

<div class="post-metadata">

**Author:** ![popolzen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@popolzen](https://www.ruby-forum.com/u/popolzen)\
**Post date:** [November 22, 2006, 4:51pm UTC](https://www.ruby-forum.com/t/another-yaml-bug/76935/2 "2006-11-22T16:51:01Z")

</div>

On 11/22/06, Vladimir M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> b: c  
> d:  
> e: f
> 
> but must be:
> 
> * * *
> 
> b: c  
> d: ~  
> e: f

Not a bug.

According to [1] the canonical representation for !!null is indeed  
‘~’, but the empty string (as well as the tokens ‘null’, ‘Null’ and  
‘NULL’) are also acceptable representations. And we needn’t worry  
about confusion with the empty string since the empty string must be  
represented with quotation marks, e.g.:

d: “”

There may be an argument that the YAML serialization of Ruby’s nil  
_should_ be ‘~’ instead of an empty string, but it is not the case  
that it _must_ be so.

Jacob F.

[1] [Null Language-Independent Type for YAML™&nbsp;Version&nbsp;1.1](http://yaml.org/type/null.html)
