Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
Create Rails Schema from JSON Variable

Is it possible to How can I generate a Rails schema from a JSON variable?

I'm looking to go from a JSON variable like this:

{
"employees":[
    {"firstName":"John", "lastName":"Doe"}, 
    {"firstName":"Anna", "lastName":"Smith"},
    {"firstName":"Peter", "lastName":"Jones"}
]
}

to having a Model called Employee with 2 fiels: firstName and lastName

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You don't generate schemas dynamically in a relational database. Even if its possible to monkey around and parse the JSON and use it to create SQL statements like:

CREATE TABLE 'employees' ...

Its just not an intelligent way to build web applications. It creates a ton of potential security issues and is not sane or maintainable.

It violates the entire way you should be using ActiveRecord - with migrations that build up the schema to a model that works for the problem domain.

If you want to store data in Postgres with an arbitrary schema use a JSON type column.

create_table :employees do |t|
  t.json 'data'
end

This will let you store whatever you want in employees.data.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!