# YAML no reorder data at loading

**URL:** <https://www.ruby-forum.com/t/yaml-no-reorder-data-at-loading/130878>\
**Category:** Ruby\
**Created:** [March 4, 2008, 6:33am UTC](https://www.ruby-forum.com/t/yaml-no-reorder-data-at-loading/130878 "2008-03-04T06:33:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ranieri\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/43a26b/32.png) [@Ranieri\_T](https://www.ruby-forum.com/u/Ranieri_T)\
**Post date:** [March 4, 2008, 6:33am UTC](https://www.ruby-forum.com/t/yaml-no-reorder-data-at-loading/130878/1 "2008-03-04T06:33:29Z")

</div>

Hi,  
I want to load the following yaml content:

Yellow: 1  
Blue: 2  
Red: 3

And build two arrays: one for keys, that must be in this order:

[‘Yellow’, ‘Blue’, ‘Red’] and another for values:

[1, 2, 3]

How can I do that?

Thanks

---

<div class="post-metadata">

**Author:** ![Ranieri\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/43a26b/32.png) [@Ranieri\_T](https://www.ruby-forum.com/u/Ranieri_T)\
**Post date:** [March 4, 2008, 8:49am UTC](https://www.ruby-forum.com/t/yaml-no-reorder-data-at-loading/130878/2 "2008-03-04T08:49:41Z")

</div>

Alle Tuesday 04 March 2008, Ranieri T. ha scritto:

> [1, 2, 3]
> 
> How can I do that?
> 
> Thanks

As far as I can tell, you can’t. This is because the notation

key: value

in YAML represents a hash, which is sorted in an arbitrary order. If you  
want  
to keep the order, the simplest way is to replace the YAML hash with a  
nested  
list:

- [Yellow, 1]
- [Blue, 2]
- [Red, 3]

I hope this helps

Stefano
