I have a JSON file, named "Config.json", that looks like this:
{ "RunEnvironment": "DEV"}
In a batch file under the same directory, I want to read the value of the "RunEnvironment" element. My batch script would look like:
if [jsonElement] == 'DEV' (
:: do something
)
Can anyone show me how to do this?
for /f "tokens=1,2 delims=:{} " %A in (file.json) do @If "%~B"=="Dev" @Echo %~A = %~Bin a batch file double the percent signs..jsonfile may carry several[jsonElement]'swithvalues on the same line and those lines may or may not contain opening or closing braces and may have trailing commas. This would mean that you would need to isolate lines containing the string first, then parse that line to determine your specific element and value within it. The answer I provided usesFindStrto isolate the lines, so that may help if my answer was not exactly what you needed.