# Incorrect yaml?

**URL:** <https://www.ruby-forum.com/t/incorrect-yaml/81408>\
**Category:** Ruby\
**Created:** [January 8, 2007, 10:24pm UTC](https://www.ruby-forum.com/t/incorrect-yaml/81408 "2007-01-08T22:24:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [January 8, 2007, 10:24pm UTC](https://www.ruby-forum.com/t/incorrect-yaml/81408/1 "2007-01-08T22:24:44Z")

</div>

Here’s a simple yaml output from the Ruby to\_yaml method:  
sample = { ‘foo’ =\> %w[a b c] }  
puts sample.to\_yaml  
=\>

---

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [January 8, 2007, 10:37pm UTC](https://www.ruby-forum.com/t/incorrect-yaml/81408/2 "2007-01-08T22:37:18Z")

</div>

## Here’s a simple yaml output from the Ruby to\_yaml method: sample = { ‘foo’ =\> %w[a b c] } puts sample.to\_yaml =\>

foo:  
-a  
-b  
-c

This does _not_ load in to the yaml module in Perl (changed to a  
one-liner for brevity):  
ruby -ryaml -e ‘puts ({%{foo} =\> %w[a b c]}).to\_yaml’ | perl -MYAML  
-0777 -e ‘YAML::Load(\<\>)’  
YAML Error: Invalid element in map  
Code: YAML\_LOAD\_ERR\_BAD\_MAP\_ELEMENT  
Line: 3

Converting a similar structure using Perl produces yaml with the list  
indented. My question is: which implementation is correct? Should the  
a,b,c list be indented? The Ruby output is read properly by Ruby, but  
not Perl. The Perl output is read properly by both.

I’ve dug thru the [yaml.org](http://yaml.org) spec, but can’t find any reference that  
tells me which is correct…

Using Redhat Enterprise Linux 4, ruby 1.8.5, perl 5.8.8 w/YAML.pm 0.62

---

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [January 8, 2007, 10:38pm UTC](https://www.ruby-forum.com/t/incorrect-yaml/81408/3 "2007-01-08T22:38:51Z")

</div>

> Here’s a simple yaml output from the Ruby to\_yaml method:  
> sample = { ‘foo’ =\> %w[a b c] }  
> puts sample.to\_yaml  
> =\>

## $ irb irb(main):001:0\> require ‘yaml’ =\> true irb(main):002:0\> sample = {‘foo’ =\> %w[a b c]} =\> {“foo”=\>[“a”, “b”, “c”]} irb(main):003:0\> puts sample.to\_yaml

foo:

- a
- b
- c  
=\> nil  
irb(main):004:0\> sample.to\_yaml  
=\> “— \nfoo: \n- a\n- b\n- c\n”

Regards,  
Rimantas

---

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [January 8, 2007, 10:45pm UTC](https://www.ruby-forum.com/t/incorrect-yaml/81408/4 "2007-01-08T22:45:53Z")

</div>

Rimantas, please see my _second_ post. First one got cut off…  
thanks…

---

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [January 8, 2007, 11:59pm UTC](https://www.ruby-forum.com/t/incorrect-yaml/81408/5 "2007-01-08T23:59:59Z")

</div>

Ahh… Thanks, why… That’s exactly the information I was looking  
for. I’ll try YAML::Syck. -dan

---

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [January 8, 2007, 11:50pm UTC](https://www.ruby-forum.com/t/incorrect-yaml/81408/6 "2007-01-08T23:50:59Z")

</div>

On Tue, Jan 09, 2007 at 06:37:20AM +0900, Dan K. wrote:

> a,b,c list be indented? The Ruby output is read properly by Ruby, but  
> not Perl. The Perl output is read properly by both.

Ruby’s YAML support is further along than YAML.pm. The YAML  
generated by Ruby’s YAML module is correct for YAML 1.0. YAML.pm  
just doesn’t know how to parse it. See example 4.19 in the spec[1].

You might try Audrey Tang’s YAML::Syck[2], which uses the same backend  
as Ruby, thus is more likely to play nice with each other.

Signed with a very pricey horsehair brush,

\_why

[1] [http://yaml.org/spec/history/2004-01-29/2004-01-29.html#id2564419](http://yaml.org/spec/history/2004-01-29/2004-01-29.html#id2564419)  
[2] [YAML-Syck-1.34 - Fast, lightweight YAML loader and dumper - metacpan.org](http://search.cpan.org/dist/YAML-Syck/)
