How do I design a ruby equivalent objects for this json structure -


i have json structure need build based on url parameters provided client. i've been building json structure out using jbuilder.encode it's getting pretty hairy.

self.query = jbuilder.encode |json|             json.query                 json.filtered                     json.filter                         json.bool                             if(search_term && username)                                 json.array!(should)                                   ........ 

how can build ruby objects convert them json based on how initialized?

below full json structure i'd capture in ruby models/poros (plain old ruby objects).

{     "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                                 }                             }                         }                     ]                 }             }         }     } } 

hmm i'm not sure poro's, 1 thing i've seen when structure starts hairy make method returns hash representation of show. have tried making query method returns hash structure , calling in jbuilder template? there's .attributes method rails returns hash attributes, have how use poro , if works purpose.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -