'Parse Json string to Classic ASP page

What is the best way to parse json string into classic asp using a library?

Dim jsonString
jsonString = {"date":"4/28/2017","custType":"100","vehicle":"1"}

Would like to have

response.write("<li> date :" & json("date") & "</li>")


Solution 1:[1]

Got it working:

Using https://github.com/rcdmk/aspJSON

Dim jsonString
jsonString = {"date":"4/28/2017","custType":"100","vehicle":"1"}

Dim jsonObj, outputObj
set jsonObj = new JSONobject
set outputObj = jsonObj.parse(jsonString)

response.write("<li> date :" & outputObj("date") & "</li>")
response.write("<li> custType :" & outputObj("custType") & "</li>")
response.write("<li> vehicle :" & outputObj("vehicle") & "</li>")

If you need to iterate through the single object use outputObj.pairs

Dim props, prop
props = outputObj.pairs
for each prop in props
    response.write prop.name & " : " & prop.value & "<br>"
next

as referenced https://github.com/rcdmk/aspJSON/issues/20

Solution 2:[2]

As a quick solution for simple json structure and escaped values, this simple function returns the key values by splitting the json string on double quotes chr(34):

function getKeyValue(JsonString,key)
    myarray=split(JsonString,key,-1,1)
    if ubound(myarray)>0 then
        myarray2=split(myarray(1),chr(34),-1,1)
        getKeyValue=myarray2(2)
    else
        getKeyValue=""
    end if
end function

usage:

response.write("<li> date :" & getKeyValue(Your_Json_String_Here,"date") & "</li>")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2