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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:53:56+00:00 2026-05-20T20:53:56+00:00

I am working on an ASP classic project where I have implemented the JScript

  • 0

I am working on an ASP classic project where I have implemented the JScript JSON class found here. It is able to interop with both VBScript and JScript and is almost exactly the code provided at json.org. I am required to use VBScript for this project by the manager of my team.

It works very well on primitives and classes defined within ASP. But I have need for Dictionary objects which from my knowledge are only available through COM interop. (via Server.CreateObject("Scripting.Dictionary")) I have the following class which represents a product: (ProductInfo.class.asp)

<%
Class ProductInfo

    Public ID
    Public Category
    Public PriceUS
    Public PriceCA
    Public Name
    Public SKU
    Public Overview
    Public Features
    Public Specs

End Class
%>

The Specs property is a Dictionary of key:value pairs. Here’s how I’m serializing it: (product.asp)

<%
dim oProd
set oProd = new ProductInfo
' ... fill in properties
' ... output appropriate headers and stuff
Response.write( JSON.stringify( oProd ) )
%>

When I pass an instance of ProductInfo to JSON.Stringify (as seen above) I get something like the following:

{
    "id": "1547",
    "Category": {
        "id": 101,
        "Name": "Category Name",
        "AlternateName": "",
        "URL": "/category_name/",
        "ParentCategoryID": 21
    },
    "PriceUS": 9.99,
    "PriceCA": 11.99,
    "Name": "Product Name",
    "SKU": 3454536,
    "Overview": "Lorem Ipsum dolor sit amet..",
    "Features": "Lorem Ipsum dolor sit amet..",
    "Specs": {}
}

As you can see, the Specs property is an empty object. I believe that the JSON stringify method knows that the Specs property is an object, so it appends the {} to the JSON string around the stringified output. Which in this case is an empty string. What I expect it to show, however is not an empty object. See below:

"Specs": {
    "foo":"bar",
    "baz":1,
    "etc":"..."
}

I believe the problem area of the JSON library is here: (json2.asp)

// Otherwise, iterate through all of the keys in the object.

for (k in value) {
    if (Object.hasOwnProperty.call(value, k)) {
        v = str(k, value);
        if (v) {
            partial.push(quote(k) + (gap ? ': ' : ':') + v);
        }
    }
}

I postulate that the problem with the above code is that it assumes that all objects inherit from the Object class. (The one that provides hasOwnProperty) However I think that it’s likely that COM objects don’t inherit from the Object class — or at least the same Object class. Or at least don’t implement whatever interface is required to do for ... in on them.

Update: While I feel it is irrelevant for the question to be answered — I expect some sort of web client to request (via http) the JSON representation of this object or a collection of this object.

tl;dr The question: What should I do to make it so that the Scripting.Dictionary can be output properly as JSON instead of failing and returning just an empty string? Do I need to ‘reinvent the wheel’ and write my own Dictionary class in VBScript that does act as a normal object in ASP?

  • 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-20T20:53:56+00:00Added an answer on May 20, 2026 at 8:53 pm

    Javascript’s for...in construct (which is used in the JSON serializer you refer to) only works on native JS objects. To enumerate a Scripting.Dictionary’s keys, you need to use an Enumerator object, which will enumerate the keys of the Dictionary.

    Now the JSON.stringify method has a nifty way of allowing custom serialization, by checking for the presence of a toJSON method on each property. Unfortunately, you can’t tack new methods on existing COM objects the way you can on native JS objects, so that’s a no-go.

    Then there’s the custom stringifier function that can be passed as second argument to the stringify method call. That function will be called for each object that needs to be stringified, even for each nested object. I think that could be used here.

    One problem is that (AFAIK) JScript is unable to differentiate VBScript types on its own. To JScript, any COM or VBScript object has typeof === 'object'. The only way I know of getting that information across, is defining a VBS function that will return the type name.

    Since the execution order for classic ASP files is as follows:

    • <script> blocks with non-default script languages (in your case, JScript)
    • <script> blocks with the default script language (in your case, VBScript)
    • <% ... %> blocks, using the default script language (in your case, VBScript)

    The following could work — but only when the JSON.stringify call is done within <% ... %> brackets, since that’s the only time when both JScript and VBScript <script> sections would both have been parsed and executed.

    The final function call would be this:

    <%
        Response.Write JSON.stringify(oProd, vbsStringifier)
    %>
    

    In order to allow JScript to check the type of a COM object, we’d define a VBSTypeName function:

    <script language="VBScript" runat="server">
        Function VBSTypeName(Obj)
            VBSTypeName = TypeName(Obj)
        End Function
    </script>
    

    And here we have the full implementation of the vbsStringifier that is passed along as second parameter to JSON.stringify:

    <script language="JScript" runat="server">
    
        function vbsStringifier(holder, key, value) {
            if (VBSTypeName(value) === 'Dictionary') {
                var result = '{';
                for(var enr = new Enumerator(value); !enr.atEnd(); enr.moveNext()) {
                    key = enr.item();
                    result += '"' + key + '": ' + JSON.stringify(value.Item(key));
                }
                result += '}';
                return result;
            } else {
            // return the value to let it be processed in the usual way
                return value;
            }
        }
    
    </script>
    

    Of course, switching back and forth between scripting engines isn’t very efficient (i.e. calling a VBS function from JS and vice versa), so you probably want to try to keep that to a minimum.


    Also note that I haven’t been able to test this, since I no longer have IIS on my machine. The basic principle should work, I’m not 100% certain of the possibility to pass a JScript function reference from VBScript. You might have to write a small custom wrapper function for the JSON.stringify call in JScript:

    <script runat="server" language="JScript">
        function JSONStringify(object) {
            return JSON.stringify(object, vbsStringifier);
        }
    </script>
    

    after which you can simply adjust the VBScript call:

    <%
        Response.Write JSONStringify(oProd)
    %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this classic ASP site which has been working fine until we updated
Working on an old site in asp classic. I want to write a function
I am working with a legacy ASP Classic solution which is load balanced (via
I'm working on updating a classic ASP web page used by a number of
Very odd problem as this is working perfectly on our old Classic ASP site.
I am working with ASP.NET doing some client side javascript. I have the following
I am working with asp.net website project that some of pages need authentication. I
When working on ASP.NET 1.1 projects I always used the Global.asax to catch all
I am working with ASP.net. I am trying to call a method that exists
I've been working with ASP.NET MVC for the last few weeks, learning as 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.