# Nested Hash Problem

**URL:** <https://www.ruby-forum.com/t/nested-hash-problem/173243>\
**Category:** Rails\
**Created:** [August 5, 2009, 3:38pm UTC](https://www.ruby-forum.com/t/nested-hash-problem/173243 "2009-08-05T15:38:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![avantec](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9e8a1a/32.png) [@avantec](https://www.ruby-forum.com/u/avantec)\
**Post date:** [August 5, 2009, 3:38pm UTC](https://www.ruby-forum.com/t/nested-hash-problem/173243/1 "2009-08-05T15:38:03Z")

</div>

Dear all,  
I have a hash  
serv\_value =\> {60=\>{“servicetype\_id”=\>4, “quantity”=\>1, “amount”=\>360.0,  
“narration”=\>“GTT”}, 6116=\>{“servicetype\_id”=\>1934, “quantity”=\>1,  
“amount”=\>42500.0, “narration”=\>“HRT.BT SHUNT”},  
78=\>{“servicetype\_id”=\>5499, “quantity”=\>1, “amount”=\>500.0,  
“narration”=\>“LIPID PROFILE”}, 6477=\>{“servicetype\_id”=\>5499,  
“quantity”=\>1, “amount”=\>500.0, “narration”=\>“XRAY CHARGES”},  
152=\>{“servicetype\_id”=\>5499, “quantity”=\>1, “amount”=\>90.0,  
“narration”=\>“VDRL”}}

I want it to rearrange such a way that I should get

serv\_value =\> {4 =\> {“quantity”=\>1, “amount”=\>360.0,  
“narration”=\>“GTT”}, 1934=\>{“quantity”=\>1, “amount”=\>42500.0,  
“narration”=\>“HRT.BT SHUNT”}, 5499 =\> {{ “quantity”=\>1, “amount”=\>500.0,  
“narration”=\>“LIPID PROFILE”}, {“quantity”=\>1, “amount”=\>500.0,  
“narration”=\>“XRAY CHARGES”}, {“quantity”=\>1, “amount”=\>90.0,  
“narration”=\>“VDRL”}} }

In this, I need to make a hash with key as servicetype\_id.

Pls help me,  
Thanks in Advance,  
Avantec
