PowerShell-合并JSON文件

时间:2015-04-16 09:06:53

标签: json powershell

如何使用PowerShell将JSON文件的一个数组的对象复制到另一个JSON文件的数组?例如,我有一个JSON文件,如:

"type":  "Employee",
"Properties":  [
                  {
                      "Name":  "Raj",
                      "Id":  "18111",
                      "email":  "emp1@company.com",
                      "Position":  "Manager",
                      "DateOfJoining":  "16.10.14",
                   }
              ],
"Description":  "Employee details"

和另一个JSON文件:

"type": "Employee",
"Properties": [
    {
    "Name": "Ram",
    "Id": "44000",
    "email":  "emp2@company.com",
    "Position":  "Admin",
    "DateOfJoining":  "10.12.14",
    },      
    {
    "Name": "Paul",
    "Id": "44002",
    "email":  "emp3@company.com",
    "Position":  "Programmer",
    "DateOfJoining":  "10.9.14",
    },
],
"Description": "Employee details"

我想将数组从第一个JSON文件复制到第二个JSON文件。

1 个答案:

答案 0 :(得分:-3)

您可以尝试这样的事情:

$c1 = Convert-FromJson (gc file1.json -raw)
$c2 = Convert-FromJson (gc file2.json -raw)
$c3 = $c1.Properties + $c2.Properties
$c3 | ConvertTo-Json