用于填充json文本文件的Batch命令

时间:2014-07-18 18:43:23

标签: json batch-file

想知道批处理命令是否可以进入json文件并设置值。例如,Json File

        { "JsonSample" : [{
          "Field1": %Value From Batch Command%,
          "Field2": %Value From Batch Command%
        }]}

1 个答案:

答案 0 :(得分:0)

您可以使用Xidel来做到这一点:

SET var1=Value1
SET var2=Value2

xidel.exe -s -e "{'JsonSample':[{'Field2':'%var1%','Field2':'%var2%'}]}"
{
  "JsonSample": [
    {
      "Field2": "Value1",
      "Field2": "Value2"
    }
  ]
}

要将其另存为json,只需重定向到文件:

xidel.exe -s -e "{'JsonSample':[{'Field2':'%var1%','Field2':'%var2%'}]}" > output.json