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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:22:04+00:00 2026-05-25T03:22:04+00:00

I’m working on a Firefox extension and I’m trying to stringify a JSON object.

  • 0

I’m working on a Firefox extension and I’m trying to stringify a JSON object.

I’m using this stringify function but I’m getting this error:

Could not convert JavaScript argument "NS_ERROR_XPC_BAD_CONVERT_JS"

I really just care about the first level or two or properties inside the object, and I don’t care about the methods / functions. Is there a simpler way to stringify an object if I don’t need all this?

Here’s the bit of code I’m using:

    var s=JSONstring.make('abc');

    try{

        Firebug.Console.log(gContextMenu);

        s = JSON.stringify(gContextMenu);

        Firebug.Console.log(s);
    }catch(e){
        Firebug.Console.log('error');
        Firebug.Console.log(e);
    }
    var s=JSONstring.make('abc');
    Firebug.Console.log(s);
    Firebug.Console.log(gContextMenu);

Here is the error in the console window:

image

This is what I was able to copy out of the Firebug console window:

http://pastebin.com/KPXceRag

Here is a screenshot of the object:

image http://img143.imageshack.us/img143/2603/pictureos.png

  • 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-25T03:22:04+00:00Added an answer on May 25, 2026 at 3:22 am

    You can define a custom function on your object called toJSON() that returns only the elements of the object you want. Somewhat counter-intuitively, your toJSON function should not return a JSON string – it just returns an object representing what should be used as the input for JSON.stringify.

    For example:

    // an object with some attributes you want and some you don't
    var o = {
        a:"value1", 
        b:"value2", 
        doCalc: function() { return this.a + " " +  this.b } 
    };
    // define a custom toJSON() method
    o.toJSON = function() { 
        return {
            a:this.a, 
            calc: this.doCalc() 
        } 
    };
    
    JSON.stringify(o); // '{"a":"value","calc":"value1 value2"}'
    

    In your case, you should be able to define this method for gContextMenu on the fly, before calling JSON.stringify. This does require you to explicitly define what you want and don’t want, but I don’t think there’s a better way.

    Edit: If you want to pull all non-method values, you could try something like this:

    o.toJSON = function() { 
        var attrs = {};
        for (var attr in this) {
            if (typeof this[attr] != "function") {
                attrs[attr] = String(this[attr]); // force to string
            }
        }
        return attrs;
    };
    

    You will probably end up with a few attributes set to "[object Object]", but if all you want is inspection, this probably isn’t an issue. You could also try checking for typeof this[attr] == "string" || typeof this[attr] == "number" if you wanted to get only those types of attributes.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I want to construct a data frame in an Rcpp function, but when I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.