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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:18:48+00:00 2026-05-29T22:18:48+00:00

I am running var n = []; jQuery.toJSON( n ); On one page I

  • 0

I am running

var n = [];
jQuery.toJSON( n );

On one page I get "[]" on the other ""[]"". On both pages I run the same jQuery version with a toJson Plugin.

In Firefox DOM I can see both arrays have the same function names, but … different:

all     b(B, A)
any     j(B, A)

all     all(iterator, context)
any     any(iterator, context)

I guess there are some Array.prototype functions before my script. That causing the arrays to be different. I can’t change the other code I have to somehow deal with this.

I tried new Array() and jQuery.makeArray(n), still same result. I actually don’t care that the arrays are not equal but how do I get the same JSON code for this? It’s getting worse if I have strings in the array: ""[\"a\", \"b\"]""

  • 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-29T22:18:49+00:00Added an answer on May 29, 2026 at 10:18 pm

    The extra quotes are caused by the

    Array.prototype.toJSON
    

    function that is defined by the Prototype library and possibly other libraries as well. This function is called by jQuery.toJSON (or JSON.Stringify() for that matter) and produces the extra quotes. If you would use

    delete Array.prototype.toJSON // remove toJSON for all Arrays
    //or
    delete n.toJSON // remove toJSON for specific Array
    

    before you do the jQuery.toJSON, that should work!

    As another suggestion, it is better to use

    JSON.stringify(object)
    

    instead of jQuery.toJSON. It is supported natively in most browsers. If you want to be sure it works everywhere, use https://github.com/douglascrockford/JSON-js, it is the basis used for the JSON.stringify() function.

    For JSON.stringify(), see https://developer.mozilla.org/En/Using_native_JSON for more info.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a counter running on one of my add input jquery functions: var
Is there an NSIS var to get the path of the currently running installer?
When running on an xhtml page, xpath doesn't seem to return any results. var
This is the same question as this: https://stackoverflow.com/questions/2890620/jquery-running-a-function-in-a-context-and-adding-to-a-variable But that question was poorly posed.
Good day! I'm running a plugin on jQuery 1.4.4 with getJSON() , after uprade
Good day! I've running plugin on jQuery 1.4.4 with getJSON() , after uprade to
I'm no jQuery expert but managed to get the effects running I required for
I'm trying to get some AJAX running with Django using jQuery. The problem is
So i'm trying to get familiar with jQuery, so i've been running some test
I have this code (running jQuery 1.4.2) var elementToAdd = $('<h3>').html('header'); var p =

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.