How to convert YAML to JSON with PowerShell Core

 
 
  • Gérald Barré

PowerShell Core doesn't provide a built-in cmdlet to parse YAML. However, there is a PowerShell module called powershell-yaml that provides the ConvertFrom-Yaml and ConvertTo-Yaml cmdlets. The following example shows how to convert a YAML file to a JSON file with PowerShell Core:

PowerShell
$InputFile = "test.yaml"
$OutputFile = "test.json"

Install-Module powershell-yaml -Scope CurrentUser
Get-Content -LiteralPath $InputFile |
    ConvertFrom-Yaml |
    ConvertTo-Json |
    Out-File -LiteralPath $OutputFile

#Resources

Do you have a question or a suggestion about this post? Contact me!

Follow me:
Enjoy this blog?Buy Me A Coffee💖 Sponsor on GitHub