Any good libraries for parsing JSON in Classic ASP? [closed] Any good libraries for parsing JSON in Classic ASP? [closed] json json

Any good libraries for parsing JSON in Classic ASP? [closed]


Keep in mind that Classic ASP includes JScript as well as VBScript. Interestingly, you can parse JSON using JScript and use the resulting objects directly in VBScript.

Therefore, it is possible to use the canonical https://github.com/douglascrockford/JSON-js/blob/master/json2.js in server-side code with zero modifications.

Of course, if your JSON includes any arrays, these will remain JScript arrays when parsing is complete. You can access the contents of the JScript array from VBScript using dot notation.

<%@Language="VBScript" %><%Option Explicit%><script language="JScript" runat="server" src='path/to/json2.js'></script><%Dim myJSONmyJSON = Request.Form("myJSON") // "[ 1, 2, 3 ]"Set myJSON = JSON.parse(myJSON) // [1,2,3]Response.Write(myJSON)          // 1,2,3Response.Write(myJSON.[0])      // 1Response.Write(myJSON.[1])      // 2Response.Write(myJSON.[2])      // 3%>


Not sure about it. Have you checked ASP extreme framework which has JSON support?


I couldn't get the extreme-evolution or Chris Nielson's suggestion to work. But, the following did work for me:

http://tforster.wik.is/ASP_Classic_Practices_For_The_21st_Century/JSON4ASP

Download the following as "json2.min.asp"

http://tforster.wik.is/@api/deki/files/2/=json2.min.asp

Add the following line to the top of your ASP file:

<script language="javascript" runat="server" src="json2.min.asp"></script>

You can then use JSON in ASP.

   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

Note: To parse through an array of items, you need to do the following:

   for each iTmp in testing       if (TypeName(iTmp))<>"JScriptTypeInfo" then            Response.Write("Item: " &  iTmp & "<br/>")       end if   next