Description
This function takes an objects and converts them into syntax highlighted Json using the Spectre Console Json Library.
Thanks to trackd for adding this!
See https://spectreconsole.net/widgets/json for more information.
Examples
Example 1
This example demonstrates how to format an array of objects into a Spectre Console Json object with syntax highlighting.
$data = @(
[pscustomobject]@{
Name = "John"
Age = 25
City = "New York"
IsEmployed = $true
Salary = 10
Hobbies = @("Reading", "Swimming")
Address = @{
Street = "123 Main St"
ZipCode = $null
}
}
)
Format-SpectreJson -Data $data
Parameters
Data
The array of objects to be formatted into Json.
Type | Required | Position | PipelineInput |
---|
[Object] | true | 1 | true (ByValue) |
Depth
The maximum depth of the Json. Default is defined by the version of powershell.
Type | Required | Position | PipelineInput |
---|
[Int32] | false | 2 | false |
NoBorder
Type | Required | Position | PipelineInput |
---|
[Switch] | false | named | false |
Border
Type | Required | Position | PipelineInput |
---|
[String] | false | 3 | false |
Color
Type | Required | Position | PipelineInput |
---|
[String] | false | 4 | false |
Title
Type | Required | Position | PipelineInput |
---|
[String] | false | 5 | false |
Width
Type | Required | Position | PipelineInput |
---|
[Int32] | false | 6 | false |
Height
Type | Required | Position | PipelineInput |
---|
[Int32] | false | 7 | false |
JsonStyle
A hashtable of Spectre Console color names and values to style the Json output.
e.g.
@{
MemberStyle = "Yellow"
BracesStyle = "Red"
BracketsStyle = "Orange1"
ColonStyle = "White"
CommaStyle = "White"
StringStyle = "White"
NumberStyle = "Red"
BooleanStyle = "LightSkyBlue1"
NullStyle = "Gray"
}
Type | Required | Position | PipelineInput |
---|
[Hashtable] | false | 8 | false |
Syntax
Format-SpectreJson [-Data] <Object> [[-Depth] <Int32>] [-NoBorder] [[-Border] <String>] [[-Color] <String>] [[-Title] <String>] [[-Width] <Int32>] [[-Height] <Int32>] [[-JsonStyle] <Hashtable>] [<CommonParameters>]