title: Rails migration to change column type from text to json (Postgresql)
body: <p>I've been trying unsuccessfully to change a column type in my Postgres database from text to json. Here's what I've tried...</p>
  
  <pre><code>class ChangeNotesTypeInPlaces &lt; ActiveRecord::Migration[5.0]
    def up
      execute 'ALTER TABLE places ALTER COLUMN notes TYPE json USING (notes::json)'
    end
  
    def down
      execute 'ALTER TABLE places ALTER COLUMN notes TYPE text USING (notes::text)'
    end
  end
  </code></pre>
  
  <p>Also...</p>
  
  <pre><code>class ChangeNotesTypeInPlaces &lt; ActiveRecord::Migration[5.0]
    def up
      change_column :places, :notes, 'json USING CAST(notes AS json)'
    end
  
    def down
      change_column :places, :notes, 'text USING CAST(notes AS text)'
    end
  end
  </code></pre>
  
  <p>Both of these return the same error...</p>
  
  <pre><code>PG::InvalidTextRepresentation: ERROR:  invalid input syntax for type json
  </code></pre>