Skip to content
ConsoleMonster
Cmdlet

Show-ConsoleJson

Module
ConsoleMonster
Inputs
System.Object
Outputs
ConsoleMonster.Layout.IWidget

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>]
#
Parameter set: All Parameter Sets

Description

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-ConsoleJson

An object as highlighted JSON

Example 2

Get-Content .\settings.json | Show-ConsoleJson -LineNumbers

A JSON file with line numbers

Parameters

-AsString SwitchParameter optional
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 optional
Returns the view instead of writing it.
-Depth Int32 optional
How many levels of objects and lists are written (default 4); deeper values are shown as one line of text.
-InputObject Object optionalposition: 0pipeline: True (ByValue)
JSON text or objects (pipeline input).
-LineNumbers SwitchParameter optional
Shows line numbers.
-MaxLines Int32 optional
The most lines shown (default 2000).
-Title String optional
A panel title, or none.
-Width Int32 optional
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.