# Format.json

**URL:** <https://www.ruby-forum.com/t/format-json/122412>\
**Category:** Rails\
**Created:** [December 7, 2007, 12:19pm UTC](https://www.ruby-forum.com/t/format-json/122412 "2007-12-07T12:19:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ratnavel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/6f9a4e/32.png) [@ratnavel](https://www.ruby-forum.com/u/ratnavel)\
**Post date:** [December 7, 2007, 12:19pm UTC](https://www.ruby-forum.com/t/format-json/122412/1 "2007-12-07T12:19:02Z")

</div>

Hi did anyone used format.json before…

If so pls, do let me know how to use it…

---

<div class="post-metadata">

**Author:** ![ratnavel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/6f9a4e/32.png) [@ratnavel](https://www.ruby-forum.com/u/ratnavel)\
**Post date:** [December 27, 2007, 6:55pm UTC](https://www.ruby-forum.com/t/format-json/122412/2 "2007-12-27T18:55:34Z")

</div>

A link to the api docs may get you started:  
[http://api.rubyonrails.org/classes/ActiveResource/Base.html#M000827](http://api.rubyonrails.org/classes/ActiveResource/Base.html#M000827)  
Also look at the code generated with scaffold. I simply added a json  
format.

def index  
@sites = Site.find(:all)

```
respond_to do |format|
  format.html # index.html.erb
  format.xml { render :xml => @sites.to_xml }

  format.json { render :json => @sites.to_json }
end

```

end

These are called with the URL:  
[http://somesite.org/index.html](http://somesite.org/index.html)  
[http://somesite.org/index.xml](http://somesite.org/index.xml)  
[http://somesite.org/index.json](http://somesite.org/index.json)

HTH  
-Dave

On Dec 7, 3:19 am, Ratnavel S. \<rails-mailing-l…@andreas-
