Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7764775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:00:03+00:00 2026-06-01T15:00:03+00:00

My app imports some csv data, and I build an array, serialize it, and

  • 0

My app imports some csv data, and I build an array, serialize it, and save it in a database field. I save it in serialize form because the data imported each time has a different structure … sometimes 3 columns, sometimes 10 columns, etc.

[[“fruit”, “price”, “weight”],
[“Apple”, 1.23, 4.5],
[“Orange”, 5.2, 3.3]]

The imported data has quotes around strings, and no quotes around numbers, so during the import I am able to preserve the type of each element.

But when I serialize it (to save in a database field) with ActiveSupport::JSON.encode(csv_data)
each element gets saved as a string

[[“fruit”, “price”, “weight”],
[“Apple”, “1.23”, “4.5”],
[“Orange”, “5.2”, “3.3”]]

so when I de-serialize it, the numeric values have been converted to strings, but I need them as numeric for the post-processing.

The problem is, each data import is different… sometimes it;s all numeric, sometimes the first column is string, sometimes 2 or 3 columns might be strings.

I don;t care if i use JSON or not — I just need a way to encode and decode the data so I can stuff it into a database field, without losing the ‘type’ durign the decode.

Should I be using some sort of xml method instead of JSON?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:00:06+00:00Added an answer on June 1, 2026 at 3:00 pm

    Marshal to the rescue!

    tmp = [["fruit", "price", "weight"], ["Apple", 1.23, 4.5], ["Orange", 5.2, 3.3]]
    dmp = Marshal.dump(tmp)
    p Marshal.load(dmp)
    # => [["fruit", "price", "weight"], ["Apple", 1.23, 4.5], ["Orange", 5.2, 3.3]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to import some XML data into my app. Now I open a
I am writing a Webkit app that imports data from an RSS feed and
My app in Django scraps and imports data from another application's HTML. I tested
I'm reading App Engine's documentation and i saw that i could nest some imports,
I am running some import code asynchronously from a simple WinForms app using a
I have a script that imports a models.py from an app, but it will
In my app, i have an import option, to read info from a .csv
I'm trying to upload some records to my local data store using appcfg.py Only
I am creating a Generate Report button for some data in my application. The
I am trying to upload a moderetly sized csv file to google app engine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.