# To\_json and attribute order?

**URL:** <https://www.ruby-forum.com/t/to-json-and-attribute-order/140722>\
**Category:** Rails\
**Created:** [June 17, 2008, 11:19pm UTC](https://www.ruby-forum.com/t/to-json-and-attribute-order/140722 "2008-06-17T23:19:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dweinand](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f17d59/32.png) [@dweinand](https://www.ruby-forum.com/u/dweinand)\
**Post date:** [June 17, 2008, 11:19pm UTC](https://www.ruby-forum.com/t/to-json-and-attribute-order/140722/1 "2008-06-17T23:19:55Z")

</div>

hello,

is there a reason why my attributes are not in the order as i declare  
them in my hash?  
two pasties to see what i mean.

code:  
[http://pastie.org/pastes/216649](http://pastie.org/pastes/216649)

result:  
[http://pastie.org/pastes/216657](http://pastie.org/pastes/216657)

the :id and :value attributes are twisted. but i need them in this  
order on the client.  
any hints whats going in here?

btw: app is still on 1.2.6. but just tested the same code on 2.1 with  
the same result.

thank you

---

<div class="post-metadata">

**Author:** ![dweinand](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f17d59/32.png) [@dweinand](https://www.ruby-forum.com/u/dweinand)\
**Post date:** [June 17, 2008, 11:23pm UTC](https://www.ruby-forum.com/t/to-json-and-attribute-order/140722/2 "2008-06-17T23:23:26Z")

</div>

On 17 Jun 2008, at 22:19, dweinand wrote:

> hello,
> 
> is there a reason why my attributes are not in the order as i declare  
> them in my hash?  
> two pasties to see what i mean.

hashes in ruby are not ordered (at least not in 1.8)

Fred

---

<div class="post-metadata">

**Author:** ![dweinand](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f17d59/32.png) [@dweinand](https://www.ruby-forum.com/u/dweinand)\
**Post date:** [June 17, 2008, 11:41pm UTC](https://www.ruby-forum.com/t/to-json-and-attribute-order/140722/3 "2008-06-17T23:41:07Z")

</div>

okay. makes sense to me.  
ok, i’ll have to find another way.

thx for the information.

On 17 Jun., 23:22, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
