Tricking Out Classic ASP With JSON – The Mandrill Experience

Using JSON with Classic ASP can be a tricky thing, but the developer of ASPJSON has made it very easy.  This library ( or include ) has made my life so much easier, but the instructions to get me started was somewhat raw and difficult for me to follow.

Since my original posting about  Tricking Out Classic ASP with JSON, I have had several people ask for the solution to SendGrid and Mandrill.  Both systems are very different, but the principals are similar.  I found Mandrill the easiest to implement.

The following code is the magic to it all, but this example is specific to Mandrill.

   jsonstring = ""  

   If Request.TotalBytes > 0 Then   
     Dim lngBytesCount   
     lngBytesCount = Request.TotalBytes   
     jsonstring = BytesToStr(Request.BinaryRead(lngBytesCount))   
   End If   

   Set oJSON = New aspJSON  
   'Load JSON string  
   jsonstring = replace(jsonstring, "mandrill_events=","")  

 ' Loop Through Records  
 for i = 0 to -1  
   str ="event")  
   straddress ="msg").item("email")  

You can download the full code sample from:

I did include the ASPJSON include file so that you would get the complete solution; but you should ensure you have the latest once you have my example working.  Goto ASPJSON to get the latest library.

Andrew Pallant (@LdnDeveloper) has been a web, database and desktop developer for over 16 years. Andrew has worked on projects that ranged from factory automation to writing business applications. Most recently he has been heavily involved in various forms for ecommerce projects. Over the years Andrew has worn many hats: Project Manager, IT Manager, Lead Developer, Supervisor of Developers and many more - See more at:

Posted in ASP, JSON, Web Tagged with: , , , ,
9 comments on “Tricking Out Classic ASP With JSON – The Mandrill Experience
  1. John says:

    Hi, Thanks for posting about this. I’m using this for a SendGrid application. Do you know if there is a way to extract the key names from the JSON? I don’t always know what the item names will be. Given this JSON

    “email”: “”,
    “timestamp”: 1386636127,
    “uid”: “123456”,
    “ip”: “”,
    “purchase”: “PO1452297845”,
    “useragent”: “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36”,
    “id”: “001”,
    “category”: [“category1″,”category2″,”category3”],
    “event”: “open”
    “uid”: “123456”,
    “ip”: “”,
    “useragent”:”Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36″,
    “email”: “”,

    id, purchase, uid, and url are all what SendGrid calls unique identifier. They could be anything or not in there at all.

    I can get the values by iterating through the object. would return the email value “” I believe, but I would like to also include the name of the key “email”, and any other keys that may be there. Do you know if there is a way to do this? I’m somewhat new to ASP and JSON. Thanks!

  2. Machiel van Rheenen says:

    Hello Andrew,

    Thank you for your knowledge sharing.
    I’m a bit out of my league on a job I have to do and I am hoping you will assist me some more to get me gooing.
    It concerns a classic ASP generaties website.
    I have to synchronise database info from two separate databases when updating on our website.
    There is this HTTP API I can Use to request data and update it on the remote database.
    I.e.: Https//
    It returns a JSON formatted string
    After updating our database. In need to do iT again throug the api on the remote site.
    Im thinking using a server.execute to a .asp file that i call after the local update.
    The .asp would call the api and decode the json.
    On returning from the server.execute a stored session variable would be used to examin/communicate the synchronisation result.

    Just dont know how to call a Url from within a .ASP and parse the json string it returns. Doh.

    Highest regards,


  3. Hi Mac;

    The way I would call a REST WebService ( JSON ) in Classic ASP is to do something like:

    Set HttpReq = Server.CreateObject(“MSXML2.ServerXMLHTTP”) “GET”, “”, False

    If you have to send data; looking into something similar, but it will be doing a PUT instead of a GET/

    Through a quick Google search I have found the following resources that I believe would help you.

    Integrating ASP.NET XML Web Services with ‘Classic’ ASP Applications
    Consuming a WSDL Webservice from ASP

  4. Chris says:

    Did you ever figure this out? Coming up against the same thing in Mandrill.


  5. Hi Chris;

    The solution is as outlined in:

    I have had feed back from 2 people letting me know it worked well for them.

    Was there a specific issue you were having? I may be able to point you in the correct direction.

    Kind Regards

    Andrew ( LdnDeveloper )

  6. Chris says:

    I think that I’m missing something that’s really apparent but I’m not getting it. Right now I’m able to loop through the json and get the values. The issue I’m having now is that an item might not exist and it get an error because it can’t be found. What I need to do is check and make sure the item exists in json before trying to get the data out.

    Example,“location”).item(“country_short”) the item location -> country_short does not exist in the json but almost every time it does but in this specific case it didn’t and my page will through an error. So what I need to do is something like:

    If exists location_country_short =“location”).item(“country_short”) then do this and if not skip it.

    Does that make sense?


  7. Hi Chris;

    I believe I know the answer, but I am going to sit down tonight and work out an example to send you.

    My email is If you can send me your email to my email, I will respond to you directly.

    Kind Regards


  8. The is essentially a dictionary. Since it is a dictionary, you can use calls like exists which will return you true or false.

    The following is an example of how you might use it.

    if“location”) then
    ‘ Get Location Info
    if“location”).exists(“country_short”) then
    str =“location”).item(“country_short”)
    end if
    end if

  9. Machiel van Rheenen says:

    Dear Andrew,

    Thank you so much!

    Highest Regards,


1 Pings/Trackbacks for "Tricking Out Classic ASP With JSON – The Mandrill Experience"
  1. […] Amendment:: Some people were asking for a solution to Mandrill and SendGrid. Both solutions are similar and therefore I selected one to publish. You can contact me if you would like more. See the following: Part II – The Mandrill Experience […]