title: Are there any libraries to manage json content in a database field of a rails app?
body: <p>I have a rails 2 app that manages a json field within a table. It needs to:</p>
  
  <ul>
  <li>Read the json</li>
  <li>Convert the json to model attributes and form fields</li>
  <li>Save edits to the form fields into the json field</li>
  <li>Add validation for some of the json values</li>
  <li>Be applicable to multiple models</li>
  </ul>
  
  <p>Currently, I have a library file that manually adds methods to extract and save into the json, like so:</p>
  
  <pre><code>module Configuration
    def configuration_json
      configuration? ? JSON.parse(self.configuration) : {}
    end
  
    def some_json_value
      if !self.configuration.nil? &amp;&amp; configuration_json["parentKey"]
        configuration_json["parentKey"]["someJsonValue"]
      end
    end
  
    def some_json_value=(val)
      new_config = configuration_json.deep_merge({
        "FeatureConfiguration" =&gt; { "someJsonValue" =&gt; val }
      })
      self.configuration = new_config.to_json
    end
  
    def some_json_value_validation
      # ...
    end
  end
  </code></pre>
  
  <p>And in the models I include this</p>
  
  <pre><code>class SomeModel &lt; ActiveRecord::Base
    include Configuration
    validate :some_json_value_validation
  
    # ...
  end
  </code></pre>
  
  <p>Is there a better/DRY-er way? Currently it's really clunky when the json structure changes, as there are quite a few steps to modify in the rails app.</p>
  
  <p>I can't change the use of the json field, as it's for configuration of another application, which is the main application that the rails app supports.</p>