Skip to content

Latest commit

 

History

History
15 lines (14 loc) · 757 Bytes

JSON.md

File metadata and controls

15 lines (14 loc) · 757 Bytes

Reading JSON in script

VB Script has no built-in support for JSON. The following code is very simple and reads values out of a JSON without concerning itself with the structure.

Private Function JSON_GetValue(JSON As String, Key As String, Optional Index As Long = 0)
   'Add a reference to Microsoft VBScript Regular Expressions 5.5 in the Edit\References... Menu
  'This returns a value from a JSON given the key.for the third element in an array set index=2
   Dim Regex As New RegExp, Matches As MatchCollection
   Regex.IgnoreCase = True
   Regex.Global = True
   Regex.Pattern = """" & Key & """\s*:\s*""(.*?)"""
   Set Matches = Regex.Execute(JSON)
   If Matches.Count>0 Then JSON_GetValue Matches.Item(Index).SubMatches(0)
End Function