[CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$Path, [string]$Output, [char]$Delimiter = ',' ) $ErrorActionPreference = 'Stop' $resolved = Resolve-Path -LiteralPath $Path -ErrorAction Stop $rows = @(Import-Csv -LiteralPath $resolved -Delimiter $Delimiter) $json = ConvertTo-Json -InputObject $rows -Depth 10 if ($Output) { $target = [IO.Path]::GetFullPath($Output) if ($target -eq $resolved.Path) { throw 'Выходной файл совпадает с входным' } [IO.File]::WriteAllText($target, $json + [Environment]::NewLine, (New-Object System.Text.UTF8Encoding($false))) Write-Host "JSON сохранён: $target" } else { Write-Output $json }