ASP JSON utility version 1.5 released

By | July 10

Its long time ago since there has been an update to the JSON utility class. Thats because its working very stable thanks to your support! Nevertheless we have a new version with new features and some minor bugfixes. The following has been updated:

0. Bugfixes

  • When a dictionary contained no items then nothing was returned ("someDict":{}). According to the JSON RFC this is not correct and results in invalid JSON. It returns null now. "someDict": null
  • The class supposed to fully support UTF-8 but it didnt 100%. e.g. chinese chars wouldnt work at all. This has been solved and works perfectly now!! Thanks to Jef Housein for his help and we welcome all asian asp developer now ;)

1. toJSON() method is default now

This is a minor improvement but makes our client code much nicer. See the difference:

  1. 'before
  2. output = (new JSON).toJSON("root", "some value", false)
  3. 'now additionally possible:
  4. output = (new JSON)("root", "some value", false)

2. supports ASP request object

Thanks to Jeremy Brown who inspired me with his extension to support the ASP’s request object. Therefore its possible now to represent the whole request object in JSON format. It includes request.form, request.cookies, request.servervariables, etc. (check its properties at w3schools). Simple example of how to access the HTTP_HOST server variable within javascript:

  1. <script>
  2.   alert(<%= (new JSON)(empty, request, false) % >.servervariables.HTTP_HOST);
  3. </script>

Yeah, new default method already in use :)
Note: All properties of the request object are exposed in lowercase (such as servervariables, form, …). Because of this extension the class also supports the IStringList and IRequestDictionary types now as well. Oh vtw, with this we can also easily access the users session from client side if neccesary:

  1. alert(<%= (new JSON)(empty, request, false) % >.session.some_session_var);

3. Using paged recordsets

Till now all records of both dynamic & staic recordsets have been returned. What if you are using a paged recordset (recordset.pageSize property)? its very likely that you only want those records of the current page. Thanks to Jef Housein this is possible now, but its functionality has to be turned on with the new recordsetPaging property. By default this behaivour so it does not break existing apps ;) Using a paged recordset would work like this:

  1. set j = new JSON
  2. j.recordsetPaging = true
  3. set RS = server.createObject("ADODB.recordset")
  4. RS.pageSize = 5
  5. '... and executing some command
  6. output = j("root", RS, false)
  7. 'output would always hold max. 5 records of RS now

4. Updated documentation

Documentation of the class has been heavily updated. Code examples have been added and most of the docs has been reviewed. Click here to see the updated doc.

Download JSON utility class 1.5.1
Download JSON utility class 1.5
(no changes needed when upgrading from 1.4)

Update 15.07.2008: v1.5 contained a bug when generating empty dictionaries (see james comment). v1.5.1 has fixed this. Thanks James!

Thanks a lot for all who helped making this little tool what it is. Dont forget that it is a major component within the ajaxed library. Using ajaxed makes your life even more easier ….

Greetings from hong kong!

6 comments on “ASP JSON utility version 1.5 released

  1. Thanks for writing such a useful component, I encountered a bug with your big fix concerning empty dictionaries:

    private sub generateDictionary(val)
    if val.count = 0 then
    toJSON empty, null, true

    This causes the JSON not to be written properly, the code below corrected the problem and displayed the results desired by your bug fix.

    Need to increment the innerCall variable at the beginning of the subroutine, to prevent the previous output from being cleared.

    private sub generateDictionary(val)
    innerCall = innerCall + 1
    if val.count = 0 then
    toJSON empty, null, true

  2. Thanks a lot james .. i fixed this and uploaded v1.5.1 .. I wonder how this could have happend cause i tested it ;)

  3. Hola,
    Here is a little json.encoded string which I’m sending via the get request_method and as I’m new to json, yet familiar enough with vbscript/asp - i need to take this string and create an object within an asp receipt page (there is more involved as I’m also sending a plethora of form field values - hence it must be done in this manner and would take too long to explain).
    I’ve taken the string ltself and laid it out in a more readable format - hopefully you can guide me as to how I would go about turning this string back into an object, in order to access it with vbscript at runtime.

    1. columns={
    2.     "columns":[
    3.         "column1",
    4.         "column2"
    5.         ],
    6.     "groups":[
    7.         {
    8.             "group":"group1",
    9.             "columns":[
    10.                 "group1.1",
    11.                 "group1.2"
    12.                 ]
    13.         },
    14.         {
    15.             "group":"group2",
    16.             "columns":[
    17.                 "group2.1",
    18.                 "group2.2"
    19.                 ]
    20.         }
    21.     ]
    22. }

    basically I’m using a dynamically created sortable list. Where the user can create x number of columns and x number of grouped columns. The user can then drag columns into grouped column lists (assigned by the ‘groups’ indicator in the code above). The columns are all the dynamically created columns which have not been dragged into the grouped columns collection.

    there is a reference link at >> (where you can fill out the fields - there isn’t any error handling at the moment). To indicate the number of columns and groups, you must first enter a numeric value into “# of columns” and create grouped columns by entering a numeric value into “# of groups” then click the “render” button.

    You’ll then be able to drag columns into the grouped columns section - in order to create a collection of columns within any single group.

    when you submit, you’ll notice that a string is sent to the ‘results.asp’ page, with the formfield elements [using javascript getElementById(eachFormField)].

    and in case you’re curious to the point of this little form page, it is in order to create a table within an existing database, where the columns are the columnHeaders, and the grouped Columns are a csv of all related columns of the same type (re: notes1, notes2, notes3 etc) from a flat file such as a tab delimited file.

  4. hi james… i see your problem but my JSON class does only VBSCRIPT to JSON … and not JSON to VBSCRIPT.

    check the comments in .. as far as i remember there are some links for the way you need. i havent tried them yet.

    hope that helps.

  5. yes, thats what i’ve been looking for also. how to convert the json string into something (probably object) in ASP classic. trully i have no idea if i have to do this by myself T_T

  6. I’m new at using Json-I want to learn how to use it for cross domain includes that I’d like to do. I downloaded the utility, but I’m sorry, I am unable to intuit how to make it interface with a recordset. Is there a dumbed-down example of that? Thanks very much. :)