ruby on rails jsonb column default value : <p>I have a model ProjectKeyword where I use jsonb datatype in the column <code>:segemnted_data</code></p>

<pre><code>class ProjectKeyword &lt; ApplicationRecord
  belongs_to :project
  belongs_to :keyword
  has_many :project_keyword_dimensions
  has_many :dimensions, through: :project_keyword_dimensions

  validates :project_id, :keyword_id, presence: true
end
</code></pre>

<p>Migration </p>

<pre><code>class AddSegemtnedDataToProjectKeywords &lt; ActiveRecord::Migration[5.0]
  def change
    add_column :project_keywords, :segmented_data, :jsonb, default: '{}'
    add_index  :project_keywords, :segmented_data, using: :gin
  end
end
</code></pre>

<p>My problem is when I create new <code>project_keyword</code> instance the default value of the <code>segmented_data</code> is a string not a hash and I cannot update this field or merge with another hash 
For example</p>

<pre><code>[12] pry(#)&gt; new_pr_keyword = ProjectKeyword.new(project_id: 1671333, keyword_id: 39155)
=&gt; #&lt;ProjectKeyword:0x007fd997641090 id: nil, project_id: 1671333, keyword_id: 39155, segmented_data: "{}"&gt;
[13] pry(#)&gt; new_pr_keyword.save!
=&gt; true
[14] pry(#)&gt; new_pr_keyword.segmented_data.update({'new_data' =&gt; 'some_data'})
NoMethodError: undefined method `update' for "{}":String
from (pry):14:in `block (3 levels) in &lt;top (required)&gt;'
</code></pre>

<p>But when I asign <code>hash</code> value to the field <code>segmented_data</code> before update then <code>update</code> method works fine.</p>

<p>For example </p>

<pre><code>[15] pry(#)&gt; new_pr_keyword.segmented_data = {'new_data' =&gt; 'some_data'}
=&gt; {"new_data"=&gt;"some_data"}
[16] pry(#)&gt; new_pr_keyword.save!
=&gt; true
[17] pry(#)&gt; new_pr_keyword.segmented_data.update({'new_data_2' =&gt; 'some_data_2'})
=&gt; {"new_data"=&gt;"some_data", "new_data_2"=&gt;"some_data_2"}
[18] pry(#)&gt; new_pr_keyword.save!
=&gt; true
</code></pre>

<p>The question is how to make default value of segmented_data to be a Hash class not a String so method update then will work straight away on this field, after object just was created.</p>
