Here's another hybrid solution using JScript. (Still save it with a .bat extension.)
@if (@CodeSection == @Batch) @then
@echo off
setlocal
set "JSONfile=test.json"
for /f "delims=" %%I in ('cscript /nologo /e:JScript "%~f0" "%JSONfile%"') do set "%%~I"
setlocal enabledelayedexpansion
echo URL: !url!
echo App: !app!
endlocal
goto :EOF
@end // end batch / begin JScript chimera
var fso = WSH.CreateObject('scripting.filesystemobject'),
JSONfile = fso.OpenTextFile(WSH.Arguments(0), 1);
eval('obj = {' + JSONfile.ReadAll() + '}');
JSONfile.Close();
function walk(tree) {
for (var i in tree) {
if (typeof tree[i] === 'object') walk(tree[i]);
else WSH.Echo(i + '=' + tree[i]);
}
}
walk(obj);
Output:
URL: ad.ifwcash.com/www/delivery/afr.php?zoneid=127&cb=2015738640
App: 61
Delayed expansion was used to prevent the &
in the URL from being evaluated.
See this big fat warning if you don't control the generation of the JSON.