Show-ConsoleJson
Shows JSON with syntax highlighting: JSON text re-indented, or objects written as JSON.
Syntax
Show-ConsoleJson
[-AsString]
[-AsWidget]
[-Depth <Int32>]
[[-InputObject] <Object>]
[-LineNumbers]
[-MaxLines <Int32>]
[-Title <String>]
[-Width <Int32>]
[<CommonParameters>]#All Parameter SetsDescription
A thin convenience over Show-ConsoleCode -Language Json. Pipeline strings are joined (so Get-Content works); when they are JSON they are re-indented, otherwise they are shown as a JSON string. Other objects are collected and written with ConsoleMonster's shared value rules to -Depth levels (default 4): dictionaries with any key type, cycles as "(cycle)", values past the depth as "…", secure strings masked and byte arrays as their size.
Examples
Example 1
Get-Process -Id $PID | Select-Object Name, Id, StartTime | Show-ConsoleJsonAn object as highlighted JSON
Example 2
Get-Content .\settings.json | Show-ConsoleJson -LineNumbersA JSON file with line numbers
Parameters
- -AsString SwitchParameter
- Writes the view as one string of plain text instead of drawing it, to keep it in a variable or a file from any script, function or PowerShell version. Without it, PowerShell 7.2+ captures a view typed at the prompt ($x = ..., > file, Out-File); inside scripts and functions, and on Windows PowerShell 5.1, the view is drawn on the screen. Piped into another command (Out-Host, Out-String, Select-String) the view goes on as plain lines, without colour. Cannot be combined with -PassThru.
- -AsWidget SwitchParameter
- Returns the view instead of writing it.
- -Depth Int32
- How many levels of objects and lists are written (default 4); deeper values are shown as one line of text.
- -InputObject Object
- JSON text or objects (pipeline input).
- -LineNumbers SwitchParameter
- Shows line numbers.
- -MaxLines Int32
- The most lines shown (default 2000).
- -Title String
- A panel title, or none.
- -Width Int32
- Lays the output out for this width instead of the terminal's.
Common Parameters
This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
For more information, see about_CommonParameters.