# To\_json syntax help

**URL:** <https://www.ruby-forum.com/t/to-json-syntax-help/120945>\
**Category:** Rails\
**Created:** [November 22, 2007, 12:35am UTC](https://www.ruby-forum.com/t/to-json-syntax-help/120945 "2007-11-22T00:35:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [November 22, 2007, 12:35am UTC](https://www.ruby-forum.com/t/to-json-syntax-help/120945/1 "2007-11-22T00:35:09Z")

</div>

How can I include the delivery\_schedule attribute in this?

```
  format.json { render :json => @campaign.to_json(:include =>

```

{:category =\> {:include =\> :subscriptions}}, :methods =\> :status) }

I tried this but I get an error:

```
 format.json { render :json => @campaign.to_json(:include =>

```

[{:category =\> {:include  
=\> :subscriptions}}, :delivery\_schedule], :methods =\> :status) }

NoMethodError (You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil.macro):  
/vendor/rails/activerecord/lib/active\_record/serialization.rb:  
55:in `add\_includes’

Note: this works (I removed the category.subscriptions include):

format.json { render :json =\> @campaign.to\_json(:include =\>  
[:category, :delivery\_schedule], :methods =\> :status) }

Is there something wrong with my nesting?
