Powershell ConverTo-Json
问题,当获取一个输入.json文件,然后尝试将其作为JSON文件放回时,它会丢失“ []”(方括号)。下面的行是我正在运行的代码和注释:
问题:输出文件丢失[]
。
$data = Get-Content 'C:\_SCRIPTS\test.json' | ConvertFrom-Json
$data.job.jobName = "Test123"
$data | ConvertTo-Json -Depth 4 | Set-Content 'C:\_SCRIPTS\test2.json'
原文:
[
{
"job":
{
"jobName": "Track_Current_Full",
"fields":
{
"jobGroupName": "MediaDistributor",
"jobTemplateLibraryName": "Media_Mover_Workflows",
"jobTemplateName": "MediaDistributor",
"jobArgs":
{
"MediaDistributor.Source.SourceAgent": "r-file-001.barf1.com",
"MediaDistributor.Source.SourceData": "g:/race2019/03_17Mel/*",
"MediaDistributor.Source.IncludeFiles": "*",
"MediaDistributor.Source.ExcludeFiles": "",
"MediaDistributor.Source.ExcludeSubdirectories": "Specified",
"MediaDistributor.Source.ExcludeSubDirList": "",
"MediaDistributor.Target.TargetAgents": "f-file-300.barf1.com",
"MediaDistributor.Target.TargetDirectory": "d:/Race2019/03_17Mel",
"MediaDistributor.Target.PathMappingOptions": "Source Host,Job Date/Time",
"MediaDistributor.Transport._sp_udp": "yes",
"MediaDistributor.Transport.UseWANAccelerator": "No",
"MediaDistributor.Transport.wANAcceleratorAggressiveness": "high",
"MediaDistributor.Transport.BandwidthFloor": "0",
"MediaDistributor.Transport.BandwidthCeiling": "0",
"MediaDistributor.Transport.BandwidthThrottleByTimeOfDay": "00:00;00:00;YYYYYYY;0;",
"MediaDistributor.Options._sp_encryption": "no",
"MediaDistributor.Options.deliveryMode": "unsigned",
"MediaDistributor.Options.CompressFiles": "yes",
"MediaDistributor.Options.followSymbolicLinks": "yes",
"MediaDistributor.Options.IncrementalTransfer": "yes",
"MediaDistributor.Options.verifyforsufficientdiskspacebeforeJobtransfersstart": "Yes",
"MediaDistributor.Options.verifytargetdirectoryexists": "no",
"MediaDistributor.NotificationAndLogging.EmailCondition": "Always",
"MediaDistributor.NotificationAndLogging.EmailTo": "",
"MediaDistributor.NotificationAndLogging.EmailCc": "",
"MediaDistributor.NotificationAndLogging.EmailBcc": "",
"MediaDistributor.NotificationAndLogging.emailJobFailureReportTo": "",
"MediaDistributor.NotificationAndLogging._sp_log_severity": "Info",
"MediaDistributor.sNMPProperties.sNMPTrapReceivers": "",
"MediaDistributor.sNMPProperties.sNMPTrapCommunityString": "",
"MediaDistributor.sNMPProperties.sNMPTrapTypes": "",
"MediaDistributor.Schedule._sp_frequency": "1 H",
"MediaDistributor.Schedule._sp_start_at": "2017/12/20 10:11:00",
"MediaDistributor.Schedule.timezone": "Europe/Skopje",
"MediaDistributor.Schedule._sp_interrupt_on_failure": "Yes",
"MediaDistributor.Schedule.priority": "High",
"MediaDistributor.Schedule.finishBefore": ""
}
}
}
}
]
转换后:
{
"job": {
"jobName": "Test123",
"fields": {
"jobGroupName": "MediaDistributor",
"jobTemplateLibraryName": "Media_Mover_Workflows",
"jobTemplateName": "MediaDistributor",
"jobArgs": {
"MediaDistributor.Source.SourceAgent": "r-file-001.barf1.com",
"MediaDistributor.Source.SourceData": "g:/race2019/03_17Mel/*",
"MediaDistributor.Source.IncludeFiles": "*",
"MediaDistributor.Source.ExcludeFiles": "",
"MediaDistributor.Source.ExcludeSubdirectories": "Specified",
"MediaDistributor.Source.ExcludeSubDirList": "",
"MediaDistributor.Target.TargetAgents": "f-file-300.barf1.com",
"MediaDistributor.Target.TargetDirectory": "d:/Race2019/03_17Mel",
"MediaDistributor.Target.PathMappingOptions": "Source Host,Job Date/Time",
"MediaDistributor.Transport._sp_udp": "yes",
"MediaDistributor.Transport.UseWANAccelerator": "No",
"MediaDistributor.Transport.wANAcceleratorAggressiveness": "high",
"MediaDistributor.Transport.BandwidthFloor": "0",
"MediaDistributor.Transport.BandwidthCeiling": "0",
"MediaDistributor.Transport.BandwidthThrottleByTimeOfDay": "00:00;00:00;YYYYYYY;0;",
"MediaDistributor.Options._sp_encryption": "no",
"MediaDistributor.Options.deliveryMode": "unsigned",
"MediaDistributor.Options.CompressFiles": "yes",
"MediaDistributor.Options.followSymbolicLinks": "yes",
"MediaDistributor.Options.IncrementalTransfer": "yes",
"MediaDistributor.Options.verifyforsufficientdiskspacebeforeJobtransfersstart": "Yes",
"MediaDistributor.Options.verifytargetdirectoryexists": "no",
"MediaDistributor.NotificationAndLogging.EmailCondition": "Always",
"MediaDistributor.NotificationAndLogging.EmailTo": "",
"MediaDistributor.NotificationAndLogging.EmailCc": "",
"MediaDistributor.NotificationAndLogging.EmailBcc": "",
"MediaDistributor.NotificationAndLogging.emailJobFailureReportTo": "",
"MediaDistributor.NotificationAndLogging._sp_log_severity": "Info",
"MediaDistributor.sNMPProperties.sNMPTrapReceivers": "",
"MediaDistributor.sNMPProperties.sNMPTrapCommunityString": "",
"MediaDistributor.sNMPProperties.sNMPTrapTypes": "",
"MediaDistributor.Schedule._sp_frequency": "1 H",
"MediaDistributor.Schedule._sp_start_at": "2017/12/20 10:11:00",
"MediaDistributor.Schedule.timezone": "Europe/Skopje",
"MediaDistributor.Schedule._sp_interrupt_on_failure": "Yes",
"MediaDistributor.Schedule.priority": "High",
"MediaDistributor.Schedule.finishBefore": ""
}
}
}
}