JSON2.ASP is a simple and minor modification to Doug Crockford's defacto standard json2.js that allows it to be utilized within VBScript code.
The modifications include the extension of the Array prototype with an enumerator and a change in the syntax for setting the global JSON object that works with ASP.
Using json2.asp is extremely easy. Just include a reference to the json.asp file in your own asp file and then call JSON.parse or JSON.stringify as required.
<script language="javascript" runat="server" src="json2.min.asp"></script>
<script language="vbscript" runat="server">
Option Explicit
Dim car: Set car = JSON.parse("{""brand"":""subaru"",""model"":""outback sport"",""year"":2003," & _
"""colour"":""green"",""accessories"":[" & _
"{""foglamps"":true},{""abs"":true},{""heatedSeats"":true}]}")
Response.Write("brand: " & car.brand & "<br/>")
Response.Write("model: " & car.model & "<br/>")
Response.Write("colour: " & car.colour & "<br/>")
Response.Write("has foglamps: " & CStr(car.accessories.get(0).foglamps) & "<br/>")
car.accessories.get(0).foglamps = false
Response.Write("has foglamps: " & CStr(car.accessories.get(0).foglamps) & "<br/>")
Response.Write("new Json: " & JSON.stringify(car) & "<br/>")
Set car = Nothing
</script>
In the above example we can see that the minified version of json2.asp has been included on the ASP page followed by a VBScript codeblock. The codeblock creates an object called car by parsing a JSON string. The object contains several string and number properties as well as an array with nested properties. Several properties are read and written before finally converting the object back to a JSON string.
If you have any questions or comments please post them to the json forum on Yahoo Groups http://tech.groups.yahoo.com/group/json/. Be sure to indicate clearly that your post is regarding json2.asp.