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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:14:34+00:00 2026-06-02T12:14:34+00:00

I’ve been having trouble figuring this out so I figured i’d ask here. I’m

  • 0

I’ve been having trouble figuring this out so I figured i’d ask here. I’m using Ruby 1.8.7 and RoR 1.2.6. I have my controller rendering this JSON:

{
  "form_id": "1",
  "form_structure": {
    "3": {
        "answer_required": "undefined",
        "title": "This is a radio group, right?",
        "cssClass": "radio",
        "values": {
            "4": {
                "value": "Yes",
                "baseline": "undefined"
            },
            "5": {
                "value": "No",
                "baseline": "undefined"
            },
            "7": {
                "value": "Maybe",
                "baseline": "undefined"
            },
            "20": {
                "value": "Test",
                "baseline": "undefined"
            }
        }
    }
  }
}

As you can see, the options under “values” are ordered by the ID from the table. Looks perfect in JSON. When I use JSON.parse on it, everything under “values” get’s all out of whack and it returns this:

{
  "form_id"=>"1",
  "form_structure"=>{
    "3"=>{
        "title"=>"This is a radio group, right?",
        "cssClass"=>"radio",
        "answer_required"=>"undefined",
        "values"=>{
            "7"=>{
                "baseline"=>"undefined",
                "value"=>"Maybe"
            },
            "20"=>{
                "baseline"=>"undefined",
                "value"=>"Test"
            },
            "4"=>{
                "baseline"=>"undefined",
                "value"=>"Yes"
            },
            "5"=>{
                "baseline"=>"undefined",
                "value"=>"No"
            }
        }
    }
  }
}

This code is used in a formbuilder that I’m making, and it wouldn’t really be nice if the form elements that a person builds don’t show up in the correct order that they built them in. Anyone have insights on how I can keep the ordering or reorder them as I output or right before then?

  • 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-02T12:14:43+00:00Added an answer on June 2, 2026 at 12:14 pm

    Here you go:

    form["form_structure"]["3"]["values"] = 
    form["form_structure"]["3"]["values"].sort {
            |a,b| a[0].to_i <=> b[0].to_i
     }
    

    This will sort the hash based on the integer value of the keys in the values hash and put the sorted hash back in the larger hash.

    If you need to keep it all still hashes use this:

     val = {}
     val = form["form_structure"]["3"]["values"].sort { 
          |a,b| a[0].to_i <=> b[0].to_i }
     ind = []
     val.each { |v| ind += [v[0]] }
     val = {}
     ind.each { |k| val[k] = form["form_structure"]["3"]["values"][k] }
     form["form_structure"]["3"]["values"] = val
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have thousands of HTML files to process using Groovy/Java and I need to

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.