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

  • Home
  • SEARCH
  • 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 7595155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:36:09+00:00 2026-05-30T21:36:09+00:00

using rails 2.3.8. I’m getting this: [ [0] 0, [1] { name => Section,

  • 0

using rails 2.3.8.

I’m getting this:

[
    [0] "0",
    [1] {
            "name" => "Section",
        "contents" => {
            "0" => {
                "name" => "RENAMED!",
                  "id" => "1"
            }
        }
    }
]

notice the [0] and the [1]

but in my post, I formatted the JSON like this:

 [ {
              "name":"Section",
              "contents":[
                {
                  "id":1,
                  "name":"RENAMED!"
                }
              ]
            }, .. more of this type of structure [

so, why is rails adding the additional array?

Here is how I’m posting the object:

$j.ajax({
type: "POST",
url: 'http://url/objects/create/',
dataType: 'text',
async: false,
data: data_obj,
success: function () {
        alert("sent");
}
});

UPDATE

data_obj = {
    "my_object":{
        "name":"hello there, I am JSON!",
        "template_id":1,
        "variables":{
            "hello":"there",
            "me":"you"
         },
        "sections":[
        {
          "name":"Section",
          "contents":[
            {
              "id":1,
              "name":"RENAMED!"
            }
          ]
        },
        {
          "name":"section2",
          "contents":[
            {
              "name":"something",
              "body":"nothing"
            },
            {
              "id":2,
              "name":"I renamed you",
              "variables":{
                "hello":"i'm amazing"
              }
            }
          ]
        }
      ],
      "attachments":[
        {
          "media_id":1
        }
      ]
    }
}
  • 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-30T21:36:11+00:00Added an answer on May 30, 2026 at 9:36 pm

    Rails is not adding the extra element to the json array. That’s happening on the browser.

    Check your javascript carefully for an “edge case” of adding an empty element to the array. Eg how are you initializing the array.

    If you’re not convinced by the above on where the bug is, add a breakpoint before the ajax call and examine the data_obj array.

    ps. it should be an array, but you’ve named it data_obj. Are you treating it as an object at some point? Are you setting the first element to be at index 1? (That would be a bug.) You should only push values onto the array.

    ADDED I think the problem is that you’re not sending the data as json.
    The default for sending data to the server is key/value pairs.

    Try

    $j.ajax({
      type: "POST",
      url: 'http://url/objects/create/',
      dataType: 'text',  // what you are expecting to be returned from server
      async: false,
      data: {json: JSON.stringify(data_obj)},
      success: function () {
        alert("sent");
      }
    });
    

    See post. You may also have to set the mime-type. The post shows how.

    alt for the structure:

     ...
     data: {my_object: JSON.stringify(data_obj.my_object)},
     ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Rails 3, I've changed the name of a table in the model like
Using Rails 2.3.8. I have added this in my controller: filter_parameter_logging :password, :password_confirmation But
I'm using rails, but doing all my Javascript unobtrusively using jQuery in application.js .
Using Rails 3.2.0 with haml and sass: I Would like to link an external
Using Rails I'm trying to get an error message like The song field can't
I am using Rails 3. There is a possible duplicate here . But it
Using Rails, I would like to add: <span class='req'>&bull;</span> within my <label> tags in
I am using Rails 2.2.2 and I would like to add an id to
I am using Rails 3.0.7 and I am trying to follow this Railscast: http://railscasts.com/episodes/182-cropping-images
Using Rails 3.0.3 in combination with gems like devise I don't get any flash

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.