title: How do I design a ruby equivalent objects for this json structure
body: <p>I have a json structure that I need to build up based on url parameters provided by a client. Currently I've been building the json structure out using <code>Jbuilder.encode</code> but it's getting pretty hairy. </p>
  
  <pre><code>self.query = Jbuilder.encode do |json|
              json.query do
                  json.filtered do
                      json.filter do
                          json.bool do
                              if(search_term &amp;&amp; username)
                                  json.array!(should) do
                                    ........
  </code></pre>
  
  <p>How can I build ruby objects so that I convert them into json based on how they are initialized?</p>
  
  <p>Below is the full json structure I'd like to capture in ruby models/poros (plain old ruby objects). </p>
  
  <pre><code>{
      "query": {
          "filtered": {
              "filter": {
                  "bool": {
                      "should": [
                          {
                              "query": {
                                  "query_string": {
                                      "query": "tablet",
                                      "fields": [
                                          "standard_analyzed_name",
                                          "standard_analyzed_message"
                                      ]
                                  }
                              }
                          },
                          {
                              "term": {
                                  "username": "feedmatic"
                              }
                          }
                      ],
                      "must": [
                          {
                              "terms": {
                                  "status_type": [
                                      "3",
                                      "4"
                                  ]
                              }
                          },
                          {
                              "range": {
                                  "created_on": {
                                      "gte": 20140712,
                                      "lte": 1405134711
                                  }
                              }
                          }
                      ]
                  }
              }
          }
      }
  }
  </code></pre>