Last active
June 10, 2024 03:28
-
-
Save navono/992727c277bf3478a06540963f48f7e9 to your computer and use it in GitHub Desktop.
parse JSON file by windows batch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: Read file "package.json" into variable string, removing line breaks. | |
set string= | |
for /f "delims=" %%x in (package.json) do set "string=!string!%%x" | |
rem Remove quotes | |
set string=%string:"=% | |
rem Remove braces | |
set "string=%string:~2,-2%" | |
rem Change colon+space by equal-sign | |
set "string=%string:: ==%" | |
rem Separate parts at comma into individual assignments | |
set "%string:, =" & set "%" | |
echo %version% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice code. Sample of package.json:
{ "dummy": "invisible", "dbpath": "c:\tmp", "dbname": "hidra" }
Some limitations:
"msg": "Hi all" <-- prohibited
output: