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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:07:57+00:00 2026-05-21T21:07:57+00:00

I have the below JSON (been snipped for space), as you can see in

  • 0

I have the below JSON (been snipped for space), as you can see in the “test” and “tooltip” I have a property that needs to contain a function “formatter” (note this JSON is read in from an XML file and converted to JSON in .NET)

{
   "test": {
      "formatter": function(){return '<b>'+ this.point.name +'<\/b>: '+ this.y +' %';}
   },
   "title": {
      "align": "center", 
      "text": "Your chart title here" 
   },
   "tooltip": {
      "formatter": function(){return '<b>'+ this.point.name +'<\/b>: '+ this.y +' %';}
   } 
}

Unfortunatly I’m getting an error on the ASPX page that produces the JSON file

There was an error parsing the JSON document. The document may not be well-formed.

This error is due to the fact that the bit after the “formatter” is not in quotation marks as it thinks it’s a string. but If I put a string around it then the front end html page that uses the JSON doesn’t see the function.

Is it possible to pass this as a function and not a string?

Many thanks.


Edit:

Thanks for the quick replys. As I said I know that the above isn’t correct JSON due to the fact that the “function(){…}” part isn’t in quote marks. The front end that reads the JSON file is 3rd party so I was wondering how I could pass the function through, I understand about the problems of injection (from a SQL point of view) and understand why it’s not possible in JSON (not worked with JSON before).

  • 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-21T21:07:57+00:00Added an answer on May 21, 2026 at 9:07 pm

    If you passed it as a string you could use Javascripts EVAL function, but EVAL is EVIL.

    What about meeting it half way and using Object Notation format ?

    This is a template jquery plugin that I use at work, the $.fn.extend shows this notation format.

    /*jslint browser: true  */
    /*global window: true, jQuery: true, $: true */
    
    (function($) {
    
        var MyPlugin = function(elem, options) {
    
            // This lets us pass multiple optional parameters to your plugin
            var defaults = {
                'text' : '<b>Hello, World!</b>', 
                'anotherOption' : 'Test Plugin'
            };
    
            // This merges the passed options with the defaults
                // so we always have a value
            this.options = $.extend(defaults, options);
            this.element = elem;
        };
    
        // Use function prototypes, it's a lot faster.
        // Loads of sources as to why on the 'tinternet
        MyPlugin.prototype.Setup = function()
        {
            // run Init code
            $(this.element).html(this.options.text);
        };
    
        // This actually registers a plugin into jQuery
        $.fn.extend({
    
            // by adding a jquery.testPlugin function that takes a 
                // variable list of options
            testPlugin: function(options) {
    
                // and this handles that you may be running
                        // this over multiple elements
                return this.each(function() {
                    var o = options;
    
                    // You can use element.Data to cache 
                                // your plugin activation stopping 
                                // running it again;
                    // this is probably the easiest way to 
                                // check that your calls won't walk all 
                                // over the dom.
                    var element = $(this);
                    if (element.data('someIdentifier'))
                    {
                        return;
                    }
    
                    // Initialise our plugin
                    var obj = new MyPlugin(element, o);
    
                    // Cache it to the DOM object
                    element.data('someIdentifier', obj);
    
                    // Call our Setup function as mentioned above.
                    obj.Setup();
                });
            }
        });
    })(jQuery);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to deserialise Scala case classes that have been serialised using lift-json.
I have been trying to find encoding for below json strings from a day.
I have the below JSON in the typeData variable that is then put into
I have a SELECT statement (see below) that gets a few items from the
I have a REST service that produces JSON results that has been verified by
I have an example json as below: { Passwd:String content, Userme:String content } how
I have a JSON array like below: var jsonArray = [{k1:v1},{k2:v2},{k3:v3},{k4:v4},{k5:v5}] I don't know
I have a working JavaScript code below which dynamically creates JSON object using JSON.parse
I have been trying several ways of displaying my json images but my solutions
I have been trying to use JSON to store settings for a program. I

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.