0

This is the VBScript code answered here to get the JSON file from computer with proper values.

Set fso = CreateObject("Scripting.FileSystemObject")

json = fso.OpenTextFile("C:\path\to\combined.json").ReadAll

Set re = New RegExp
re.Pattern = """passed"":(true|false),"
re.IgnoreCase = True

For Each m In re.Execute(json)
  passed = CBool(m.SubMatches(0))
Next

But I have a JSON file that looks like this which is online,

["AA-BB-CC-MAKE-SAME.json","SS-ED-SIXSIX-TENSE.json","FF-EE-EE-EE-WW.json","ZS-WE-AS-FOUR-MINE.json","DD-RF-LATERS-LATER.json","FG-ER-DC-ED-FG.json"]

How to download this JSON file and get the values to five variables using either VBScript or batch file?

Compo
  • 30,301
  • 4
  • 20
  • 32
Codename K
  • 694
  • 2
  • 21
  • 46
  • 1
    check this - https://stackoverflow.com/questions/28143160/how-can-i-download-a-file-with-batch-file-without-using-any-external-tools and this - https://stackoverflow.com/questions/47048992/parse-and-store-text-from-a-json-file-in-windows-batch-script – npocmaka Jul 19 '18 at 21:46
  • 5
    Consider using PowerShell for this. You life will become a lot easier. – Ansgar Wiechers Jul 19 '18 at 21:50

1 Answers1

1

Here is an example for downloading a json from internet and parse it :

Dim http,URL
URL = "http://ip-api.com/json/"
Set http = CreateObject("Msxml2.XMLHTTP")
http.open "GET",URL,False
http.send
strJson = http.responseText

Set j = ParseJson(strJson)
Result = "IP =" & j.query & vbCrlf &_
"ISP = "& j.isp & vbCrlf &_
"Country = "& j.country & vbCrlf &_
"TimeZone = "& j.timezone

Wscript.echo Result
'--------------------------------------------------------
Function ParseJson(strJson)
    Set html = CreateObject("htmlfile")
    Set window = html.parentWindow
    window.execScript "var json = " & strJson, "JScript"
    Set ParseJson = window.json
End Function
'--------------------------------------------------------

You can give a try for this code :

Dim http,URL
URL = "https://privateURL/jsonfile/"
Set http = CreateObject("Msxml2.XMLHTTP")
http.open "GET",URL,False
http.send
strJson = http.responseText
Result = Extract(strJson,"(\x22(.*)\x22)")
Arr = Split(Result,",")
For each Item in Arr
    wscript.echo Item
Next
'******************************************
Function Extract(Data,Pattern)
   Dim oRE,oMatches,Match,Line
   set oRE = New RegExp
   oRE.IgnoreCase = True
   oRE.Global = True
   oRE.Pattern = Pattern
   set oMatches = oRE.Execute(Data)
   If not isEmpty(oMatches) then
       For Each Match in oMatches  
           Line = Line & Trim(Match.Value) & vbCrlf
       Next
       Extract = Line
   End if
End Function
'******************************************
Hackoo
  • 15,943
  • 3
  • 28
  • 59