title: How to get json response in rails api
body: <p>I want to display all programmes which I got from a query as json response. I'm getting the programmes, but don't know how to render them through json. I'm using the <code>jbuilder</code> gem and created a <code>create.json.buider.rb</code> file. In my query I'm getting everything correctly, but I'm not receiving a JSON response with whatever details in I have in the query.</p>
  
  <p>This is my controller. I have tried it like this but I'm not getting a json response. Only a status as 200.</p>
  
  <pre><code>class Api::V1::Categories::ProgrammesController &lt; ApiController
    respond_to :json
    def category
      @category=Category.all
      @programmes=Programme.joins(:category).find_by(category_id: params[:category_id])
      if @programmes.present?
        render :json=&gt; {:message=&gt;"Programme not exists "}, :status=&gt;422
      else
        render :json =&gt; @programmes
      end
    end
  end
  </code></pre>
  
  <p>My <code>create.json.jbuilder</code> file:</p>
  
  <pre><code>json.programmes @programmes
  </code></pre>