# Ruby JSON Problem

**URL:** <https://rubytalk.org/t/ruby-json-problem/69155>\
**Category:** ruby-talk\
**Created:** [14 February 2014 08:42 UTC](https://rubytalk.org/t/ruby-json-problem/69155 "2014-02-14T08:42:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [14 February 2014 08:42 UTC](https://rubytalk.org/t/ruby-json-problem/69155/1 "2014-02-14T08:42:57Z")

</div>

Hello,

I'am new to Ruby and JSON, and having some trouble with it. I try to get  
JSON Objects from the Toodledo API 2.0. They say they are working with  
JSON objects, but I guess they are using Arrays as well, now I dont know  
how to get the elemnts or objects inside the Array, I can use  
"pretty\_generate", but not json["id"] to just get the id of the task.  
My goal is, to get the elements and beeing able to format them, to use  
them in haml and make it look good.

first attempt:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;get '/save' do  
&nbsp;&nbsp;&nbsp;response = RestClient.get  
'[http://api.toodledo.com/2/tasks/get.php?key=da21e24e2a00ba9d45008974aed00\*\*\*;modafter=1234567890;fields=folder,star,priority](http://api.toodledo.com/2/tasks/get.php?key=da21e24e2a00ba9d45008974aed00***;modafter=1234567890;fields=folder,star,priority)',  
{:accept =\> :json}  
&nbsp;&nbsp;test = JSON.parse(response)  
&nbsp;&nbsp;test.to\_json  
&nbsp;&nbsp;&nbsp;blub = JSON.pretty\_generate(test)  
&nbsp;&nbsp;&nbsp;test1 = blub[1..-2]  
&nbsp;&nbsp;puts test1

Someone told me "RestClient.get" isn't very practial, so I tried :

get '/test' do  
&nbsp;&nbsp;&nbsp;res =  
Net::HTTP.get\_response(URI('[http://api.toodledo.com/2/tasks/get.php?key=da21e24e2a00ba9d45008974aed00\*\*\*;modafter=1234567890;fields=folder,star,priorityl](http://api.toodledo.com/2/tasks/get.php?key=da21e24e2a00ba9d45008974aed00***;modafter=1234567890;fields=folder,star,priorityl)'))  
&nbsp;&nbsp;&nbsp;p res.body

but can only output one Character.

This is the JSON Data i get from toodledo:  
[{"num":"4","total":"4"},{"id":"11980343","title":"Add some items to  
your todo  
list","modified":1391670256,"completed":0,"folder":"0","priority":"2","star":"0"},{"id":"11980345","title":"Visit  
the Settings section and configure your  
account","modified":1391670256,"completed":0,"folder":"0","priority":"1","star":"0"},{"id":"11980347","title":"Watch  
our tutorial videos in the Help  
section","modified":1391670256,"completed":0,"folder":"0","priority":"3","star":"1"},{"id":"12607789","title":"test","modified":1392285802,"completed":0,"folder":"0","priority":"0","star":"0"}]

I'am desperate for help now 😃

Thank you in advance

Benny

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
