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 4061442
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:28:08+00:00 2026-05-20T15:28:08+00:00

I am using Ruby on Rails 3 and I would like to handle properly

  • 0

I am using Ruby on Rails 3 and I would like to handle properly web service responses finding a compromise between performance and utility\maneuverability.

I have to decide what type of response my web service must return back to the web client application. I am using JSON for trasmitting data and I would know if it is better to use hashes (for these I have to do extra work) or arrays.

For example I have this response:

[
  {
    "accounts" => {
      [
        "account" => {
          "id"   => 45, 
          "name" => "Test_name45", 
          "..."  => ..."
        }
        "account" => {
          "id"   => 60, 
          "name" => "Test_name60", 
          "..."  => ..."
        }
       ]
     }
   }, 
   {
     "other"  => {
       "sub_other" => {...}
     }
   }
]

I would like to use something like (no array in “accounts”, from “account” to “id”)

  {
    "accounts" => {
      "45" => { 
        "name" => "Test_name45", 
        "..."  => ..."
      }
      "60" => {
        "name" => "Test_name60", 
        "..."  => ..."
      }
   }, 
   {
     "other"  => {
       "sub_other" => {...}
     }
   }

but the latter means more work for the web service…

How to make that? Any advice?

  • 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-05-20T15:28:09+00:00Added an answer on May 20, 2026 at 3:28 pm

    I would use whichever data structure makes sense. If you have a list of things then use an array where each element is a thing. I would probably simplify your data structure to something like this:

    {
      "accounts": [
        {
          "id":   45, 
          "name": "Test_name45", 
          "...":  "..."
        },
        {
          "id":   60, 
          "name": "Test_name60", 
          "...":  "..."
        }
      ],
      "other": {
        "sub_other": {"...": "..."}
      }
    }
    

    Now, accounts is just an array of objects–no need to go looking things up by key. In Ruby this translates nicely:

    ruby-1.9.2-p136 :001 > data = JSON.parse(json)
     => {"accounts"=>[{"id"=>45, "name"=>"Test_name45", "..."=>"..."}, {"id"=>60, "name"=>"Test_name60", "..."=>"..."}], "other"=>{"sub_other"=>{"..."=>"..."}}}
    ruby-1.9.2-p136 :002 > data["accounts"].each { |acct| puts acct["name"] }
    Test_name45
    Test_name60
     => [{"id"=>45, "name"=>"Test_name45", "..."=>"..."}, {"id"=>60, "name"=>"Test_name60", "..."=>"..."}]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to build a simple REST web service (using Ruby on Rails).
I am using Ruby on Rails 3.1.0 and I would like to properly generate
I am using Ruby on Rails 3 and I would like to handle user
I am using Ruby on Rails 3 and I would like to handle models
I am building web applications using Ruby on Rails and I would like to
I am using Ruby on Rails 3.1 and I would like to handle my
I am using Ruby on Rails v3.2.2 and I would like to handle an
I am using Ruby on Rails 3.2.2 and I would like to know if
I am using Ruby on Rails 3.2.2 and I would like to know what
I am using Ruby on Rails 3.2.2 and I would like to know if

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.