1. Stephen Holsinger
  2. stringify-dictionary


stringify-dictionary /

Filename Size Date modified Message
2.3 KB
955 B

About stringifyDictionary

This is a collection of helper functions that aim to help serialize dictionaries while using the JSON2 library from: ASP Xtreme Evolution. The problem with that library is that it fails to serialize Scripting.Dictionary objects.

stringifyDictionary was written by Stephen Holsinger sholsinger@gmail.com and is provided without any warranty of any kind. It is released under the GPL version 3 license. Please keep this readme file with any distribution of this code.


To install this project just save the stringifyDictionary.asp file to your project directory (probably within an <kbd>/includes/</kbd> directory. Then include it in your script file.

Use Cases / Examples

If you're stringifying a complex object with a property that is a Dictionary then you'll find that JSON.stringify (when using the AXE library's object) doesn't properly stringify Dictionary objects. Instead, you get an empty object representation. (e.g. <code>{}</code>) To fix that, you can do a find and replace on the known bad Dictionary representation like this:

dim spaces: spaces = 2
dim strJSON: strJSON = JSON.stringify( objectInstance, Nothing, spaces)
prodJSON = replace(strJSON, """Dict"": {}", stringifyDictionary("Dict", objectInstance.Dict, spaces * 2))

JScript Implementation

I have not had time to convert this into a JScript function. Feel free to fork this and make a JScript version of both functions. If you do manage to do that, it can be used like this:

var strJSON = JSON.stringify( objectInstance, stringifyDictionary, spaces)

See that? No string replacement necessary. The only known caveat being that indentation will likely fail on the dictionary. If you don't care how the JSON looks, then this is not a problem.

Known Issues

  • The closing <code>}</code> for the <code>Dictionary</code> serialization will be the same number of indentations as the properties it contains. I didn't have time to figure out how to deal with that without adding another argument; which I don't want to do.