ConvertTo-Json
Turn objects into JSON
Get-ChildItem -File | Select-Object Name, Length | ConvertTo-Json
- Works on
- WindowsLinuxmacOS
- PowerShell
- 5.1 and later
- Reference
- Microsoft Learn: ConvertTo-Json
- All versions Only 2 levels of nesting are kept by default. Add -Depth 10 for deeper data. PowerShell 7.1+ warns when it cuts something off.
Makes JSON. For nested data, add -Depth 5 (or higher). Without it, anything deeper than 2 levels is cut off and shown as type names. Windows PowerShell 5.1 does this silently.
Try this
Get-Date | ConvertTo-Json