# YAML interpretation

**URL:** <https://www.ruby-forum.com/t/yaml-interpretation/172565>\
**Category:** Ruby\
**Created:** [July 23, 2009, 10:27am UTC](https://www.ruby-forum.com/t/yaml-interpretation/172565 "2009-07-23T10:27:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gganesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e95f7d/32.png) [@gganesh](https://www.ruby-forum.com/u/gganesh)\
**Post date:** [July 23, 2009, 10:27am UTC](https://www.ruby-forum.com/t/yaml-interpretation/172565/1 "2009-07-23T10:27:52Z")

</div>

I have one array in ruby as,

arr= [1, 2, ‘5’, ‘one’, ‘two’, ‘three’, “4,6”]

as after doing arr.to\_yaml, it prints as,

* * *

- 1
- 2
- “5”
- one
- two
- three
- “4,6”

This is my problem. It shows “4,6” as string (double-quoted) and  
(one,two) are non-quoted which itself as string. I am passing this  
string to some else database program which need clear distinction  
between string and integer.

I require the result set as,

* * *

- 1
- 2
- “5”
- “one”
- “two”
- “three”
- “4,6”

Does yaml have any provision so that i can achieve the result set in  
above consistent format?

---

<div class="post-metadata">

**Author:** ![gganesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e95f7d/32.png) [@gganesh](https://www.ruby-forum.com/u/gganesh)\
**Post date:** [July 23, 2009, 1:07pm UTC](https://www.ruby-forum.com/t/yaml-interpretation/172565/2 "2009-07-23T13:07:09Z")

</div>

On Jul 23, 2009, at 01:27 , Karan R. wrote:

> - one
> 
> above consistent format?  
> yaml only provides the extra characters when the result would be  
> ambiguous. “- one” can’t be seen as anything other than an array  
> element with the string one in it. “- 4,6” is ambiguous, so yaml  
> provides the extra quotes to disambiguate. I suggest you use a real  
> yaml parser instead of relying on regexps and duct tape. The spec is  
> well written and very clear about such things.

---

<div class="post-metadata">

**Author:** ![gganesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e95f7d/32.png) [@gganesh](https://www.ruby-forum.com/u/gganesh)\
**Post date:** [July 23, 2009, 1:35pm UTC](https://www.ruby-forum.com/t/yaml-interpretation/172565/3 "2009-07-23T13:35:26Z")

</div>

Ryan D. wrote:

> On Jul 23, 2009, at 01:27 , Karan R. wrote:
> 
> > - one
> > 
> > above consistent format?  
> > yaml only provides the extra characters when the result would be  
> > ambiguous. “- one” can’t be seen as anything other than an array  
> > element with the string one in it. “- 4,6” is ambiguous, so yaml  
> > provides the extra quotes to disambiguate. I suggest you use a real  
> > yaml parser instead of relying on regexps and duct tape. The spec is  
> > well written and very clear about such things.

Hi Ryan,

Thanks for suggestion. But I am not clear about real yaml parser. As i  
am using yaml package in ruby.

Could you please elaborate?

---

<div class="post-metadata">

**Author:** ![gganesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e95f7d/32.png) [@gganesh](https://www.ruby-forum.com/u/gganesh)\
**Post date:** [July 23, 2009, 5:39pm UTC](https://www.ruby-forum.com/t/yaml-interpretation/172565/4 "2009-07-23T17:39:06Z")

</div>

On Thu, Jul 23, 2009 at 11:35 AM, Karan R.[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > yaml parser instead of relying on regexps and duct tape. The spec is  
> > well written and very clear about such things.
> 
> Hi Ryan,
> 
> Thanks for suggestion. But I am not clear about real yaml parser. As i  
> am using yaml package in ruby.

What is the other person’s database program using to process the file?  
(“regexps and duct tape” or “a real yaml parser”)

---

<div class="post-metadata">

**Author:** ![gganesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e95f7d/32.png) [@gganesh](https://www.ruby-forum.com/u/gganesh)\
**Post date:** [July 23, 2009, 8:32pm UTC](https://www.ruby-forum.com/t/yaml-interpretation/172565/5 "2009-07-23T20:32:48Z")

</div>

On Jul 23, 2009, at 04:35 , Karan R. wrote:

> > yaml parser instead of relying on regexps and duct tape. The spec is  
> > well written and very clear about such things.
> 
> Hi Ryan,
> 
> Thanks for suggestion. But I am not clear about real yaml parser. As i  
> am using yaml package in ruby.
> 
> Could you please elaborate?

As you said: “I am passing this string to some else database program  
which need clear distinction between string and integer”

SOMEONE is not using a real yaml parser… since yaml DOES have a  
clear distinction between strings and integers.

---

<div class="post-metadata">

**Author:** ![gganesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e95f7d/32.png) [@gganesh](https://www.ruby-forum.com/u/gganesh)\
**Post date:** [July 24, 2009, 7:37am UTC](https://www.ruby-forum.com/t/yaml-interpretation/172565/6 "2009-07-24T07:37:19Z")

</div>

unknown wrote:

> What is the other person’s database program using to process the file?  
> (“regexps and duct tape” or “a real yaml parser”)

Other database program expecting only the string, like,

* * *

- 1
- 2
- “5”
- “one”
- “two”
- “three”
- “4,6”

Its treats as the “string”, not the “yaml string”.

---

<div class="post-metadata">

**Author:** ![gganesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e95f7d/32.png) [@gganesh](https://www.ruby-forum.com/u/gganesh)\
**Post date:** [July 24, 2009, 4:30pm UTC](https://www.ruby-forum.com/t/yaml-interpretation/172565/7 "2009-07-24T16:30:05Z")

</div>

On Jul 23, 2009, at 22:36 , Karan R. wrote:

> > > Thanks for suggestion. But I am not clear about real yaml parser.
> 
> - 1
> - 2
> - “5”
> - “one”
> - “two”
> - “three”
> - “4,6”
> 
> Its treats as the “string”, not the “yaml string”.

then the database program is wrong. the yaml is correct. you should  
fix what is wrong, not what is correct.
