Blog
Wild & Free Tools

Convert YAML to JSON in PowerShell — Three Free Methods

Last updated: March 2026 5 min read
Quick Answer

Table of Contents

  1. Method 1 — powershell-yaml Module
  2. Method 2 — Python One-Liner from PowerShell
  3. Method 3 — Browser Converter (Zero Install)
  4. Common ConvertTo-Json Pitfalls
  5. Frequently Asked Questions

PowerShell does not include a native YAML parser, but three free approaches cover every common scenario. The powershell-yaml module gives you native cmdlets. Python (available on most developer machines) works as a one-liner fallback. And a browser-based converter handles one-off conversions with zero install.

Method 1 — powershell-yaml Module (Native PowerShell)

The powershell-yaml module adds ConvertFrom-Yaml and ConvertTo-Yaml cmdlets that integrate naturally with the PowerShell pipeline.

Install:

Install-Module -Name powershell-yaml -Scope CurrentUser

If you get an execution policy error:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Convert a YAML string:

$yaml = @"
server:
  host: localhost
  port: 8080
debug: false
"@

$yaml | ConvertFrom-Yaml | ConvertTo-Json

Convert a YAML file:

Get-Content config.yaml -Raw | ConvertFrom-Yaml | ConvertTo-Json -Depth 10

Save output to file:

Get-Content config.yaml -Raw | ConvertFrom-Yaml | ConvertTo-Json -Depth 10 | Out-File config.json

The -Depth parameter on ConvertTo-Json defaults to 2 in older PowerShell versions. For YAML with more than 2 levels of nesting, always pass -Depth 10 (or higher) to avoid truncation where deep objects appear as literal "System.Collections.Hashtable" strings.

Method 2 — Python One-Liner (No PS Module Install Required)

If installing PowerShell modules is restricted (corporate environments, locked-down systems), Python is usually available. Call it from PowerShell:

python3 -c "import sys,yaml,json; print(json.dumps(yaml.safe_load(open(sys.argv[1])),indent=2))" config.yaml

Or pipe the YAML string directly:

$yaml = Get-Content config.yaml -Raw
$yaml | python3 -c "import sys,yaml,json; data=yaml.safe_load(sys.stdin.read()); print(json.dumps(data,indent=2))"

If PyYAML is not installed: pip install pyyaml

Save to a file:

python3 -c "import sys,yaml,json; print(json.dumps(yaml.safe_load(open(sys.argv[1])),indent=2))" config.yaml | Out-File config.json
Sell Custom Apparel — We Handle Printing & Free Shipping

Method 3 — Browser Converter (No Install, Any Windows Machine)

For one-off conversions, open the free YAML to JSON converter in any browser. Paste the YAML content, click Convert, copy the JSON output.

This requires no PowerShell modules, no Python, no admin rights, and works on any Windows machine with a browser. The conversion runs locally in the browser — nothing is uploaded.

Use this when: you are on a machine where you cannot install modules, you need a quick check during debugging, or you want to verify expected JSON output before writing a PowerShell script that depends on the structure.

Common ConvertTo-Json Pitfalls to Avoid

Depth truncation: The default -Depth is 2 in Windows PowerShell 5.1, 100 in PowerShell 7+. Always specify -Depth 10 or higher for anything more than two levels deep.

# Bad — may truncate nested objects
ConvertTo-Json

# Good
ConvertTo-Json -Depth 10

Encoding issues with Out-File: PowerShell's Out-File defaults to UTF-16 on older versions. Specify UTF-8 explicitly to avoid JSON consumers choking on the BOM:

ConvertTo-Json -Depth 10 | Out-File config.json -Encoding utf8

Numbers vs strings: YAML auto-detects types. After ConvertFrom-Yaml, a YAML value of 8080 becomes an integer in the PowerShell object. ConvertTo-Json will output it as an unquoted number — which is correct. If you need it as a string, quote it in the YAML source: port: "8080".

Convert YAML to JSON Without Installing Anything

Paste your YAML into the browser converter and click Convert. No PowerShell module, no Python, no admin rights needed.

Open Free YAML to JSON Converter

Frequently Asked Questions

How do I convert YAML to JSON in PowerShell?

Install the powershell-yaml module (Install-Module -Name powershell-yaml), then pipe your YAML through: Get-Content file.yaml -Raw | ConvertFrom-Yaml | ConvertTo-Json -Depth 10. The -Depth 10 flag prevents deep objects from being truncated.

Why does ConvertTo-Json show "System.Collections.Hashtable" instead of the actual data?

The -Depth parameter on ConvertTo-Json defaults to 2 in Windows PowerShell 5.1. Any object deeper than 2 levels is serialized as its .NET type name instead of its contents. Add -Depth 10 (or higher) to ConvertTo-Json to fix this.

Can I convert YAML to JSON in PowerShell without installing a module?

Yes, two options: (1) call Python from PowerShell: python3 -c "import sys,yaml,json; print(json.dumps(yaml.safe_load(sys.stdin.read()),indent=2))" — this requires Python + pyyaml but no PS module. (2) use a browser-based converter for one-off conversions with zero install.

Does PowerShell 7 have built-in YAML support?

No. Neither Windows PowerShell 5.1 nor PowerShell 7 includes a native YAML parser. You need the powershell-yaml module from the PowerShell Gallery, or call an external tool like Python or yq.

Tyler Mason
Tyler Mason File Format & Converter Specialist

Tyler spent six years in IT support where file format conversion was a daily challenge.

More articles by Tyler →
Launch Your Own Clothing Brand — No Inventory, No Risk