# To\_json on array of hashes

**URL:** <https://www.ruby-forum.com/t/to-json-on-array-of-hashes/145306>\
**Category:** Rails\
**Created:** [August 7, 2008, 7:47pm UTC](https://www.ruby-forum.com/t/to-json-on-array-of-hashes/145306 "2008-08-07T19:47:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sgudibanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@sgudibanda](https://www.ruby-forum.com/u/sgudibanda)\
**Post date:** [August 7, 2008, 7:47pm UTC](https://www.ruby-forum.com/t/to-json-on-array-of-hashes/145306/1 "2008-08-07T19:47:13Z")

</div>

Hi,

I need to convert my array of hashes to json:

```
             edu_items.each do |edu|
      @education[i] = { "degree" => "xxx",
      "major" => "xxx",
      "name" => "yyy",
             "start_date" => "Xxxx",
      "end_date" => "xxx",
                        "notes" => "xxxx" }
                  i = i + 1
   end

```

Number of items in edu\_items can vary, but the number of fields in each  
item is fixed and are defined in that loop. All values are strings.

I want to convert the formed array of hashes to json so that i can pass  
them down to a form and get them back too.

I was using : @education.to\_json(nil,1) to do so. But it fails if number  
of items increase. I feel it gets truncated or something…not sure  
though.

Can someone advise me ?

Regards,  
SG
