Skip to content

Commit 5e37d37

Browse files
committed
refactor: 优化Convert-JsoncToJson函数中的JSON验证逻辑
将原有的try-catch结构替换为Test-Json函数进行验证,并添加了针对$schema的调试信息
1 parent ecb7431 commit 5e37d37

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

psutils/modules/string.psm1

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,9 @@ function Convert-JsoncToJson {
108108
$jsonContent = $jsonContent -replace ',\s*([}\]])', '$1'
109109

110110
# 转换内容为JSON对象以验证有效性
111-
try {
112-
$jsonContent | ConvertFrom-Json| Out-Null
113-
}
114-
catch {
111+
if ( -not (Test-Json -Json $jsonContent -ErrorAction SilentlyContinue)) {
112+
Write-Debug '目前7.5.0版本,Test-Json无法处理包含$schema的json'
115113
Write-Error "转换失败: $_"
116-
return
117114
}
118115

119116
# 输出结果
@@ -122,7 +119,7 @@ function Convert-JsoncToJson {
122119
Write-Host "转换成功,结果已保存到: $OutputFilePath"
123120
}
124121
else {
125-
$jsonContent
122+
$jsonContent
126123
}
127124
}
128125

0 commit comments

Comments
 (0)