I'm working with JSONs and I'm having trouble correctly passing these JSONs as arguments with spaces in it to a subroutine.
The following simple JSON, {"a": 1, "b": 2}, is working fine:
Code: Select all
SET json={^^^"a^^^": 1^^^, ^^^"b^^^": 2}
SETLOCAL ENABLEDELAYEDEXPANSION
CALL :Info "!json!"
ENDLOCAL
EXIT /B 0
:Info
ECHO %~1
EXIT /B
Code: Select all
{^"a^": 1^, ^"b^": 2}
The following simple JSON with spaces in the attribute's values, {"a": "a b c", "b": "x y z"}, is NOT working correctly:
Code: Select all
SET json={^^^"a^^^": ^^^"a b c^^^"^^^, ^^^"b^^^": ^^^"x y z^^^"}
SETLOCAL ENABLEDELAYEDEXPANSION
CALL :Info "!json!"
ENDLOCAL
EXIT /B 0
:Info
ECHO %~1
EXIT /B
Code: Select all
{^"a^": ^"a
Code: Select all
{^"a^": ^"a b c^"^, ^"b^": ^"x y z^"}
Code: Select all
"{^^"a": ^"a b c^"^, ^"b^": ^"x y z^"}"
Does anyone know how I can have my script output the expected/desired output as shown above?