简体   繁体   English

PowerShell-合并JSON文件

[英]PowerShell- Merging JSON files

How to copy the objects of one array of a JSON file to an array of another JSON file using PowerShell? 如何使用PowerShell将JSON文件的一个数组的对象复制到另一个JSON文件的数组? For Example I have one JSON file like: 例如,我有一个JSON文件,例如:

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

and another JSON file as: 另一个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"

I want to copy the arrays from 1st JSON file to the 2nd JSON file. 我想将数组从第一个JSON文件复制到第二个JSON文件。

You can try something like this: 您可以尝试如下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM