Skip to content

Format-SpectreJson

Synopsis

Formats an array of objects into a Spectre Console Json.
Thanks to trackd for adding this. Spectre json example


Description

This function takes an array of objects and converts them into Json using the Spectre Console Json Library.


Examples

This example formats an array of objects into a table with a double border and the accent color of the script.

$data = @(
    [pscustomobject]@{
        Name = "John"
        Age = 25
        City = "New York"
        IsEmployed = $true
        Salary = 10
        Hobbies = @("Reading", "Swimming")
        Address = @{
            Street = "123 Main St"
            ZipCode = $null
        }
    },
    [pscustomobject]@{
        Name = "Jane"
        Age = 30
        City = "Los Angeles"
        IsEmployed = $false
        Salary = $null
        Hobbies = @("Painting", "Hiking")
        Address = @{
            Street = "456 Elm St"
            ZipCode = "90001"
        }
    }
)
Format-SpectreJson -Data $data -Title "Employee Data" -Border "Rounded" -Color "Green"

Parameters

Data

The array of objects to be formatted into Json.

TypeRequiredPositionPipelineInput
[Object]true1true (ByValue)

Depth

TypeRequiredPositionPipelineInput
[Int32]false2false

Title

The title of the Json.

TypeRequiredPositionPipelineInput
[String]false3false

Border

The border style of the Json. Default is “Rounded”.

Valid Values:

  • Ascii
  • Double
  • Heavy
  • None
  • Rounded
  • Square
TypeRequiredPositionPipelineInput
[String]false4false

Color

The color of the Json border. Default is the accent color of the script.

TypeRequiredPositionPipelineInput
[String]false5false

Width

The width of the Json panel.

TypeRequiredPositionPipelineInput
[Int32]false6false

Height

The height of the Json panel.

TypeRequiredPositionPipelineInput
[Int32]false7false

Expand

TypeRequiredPositionPipelineInput
[Switch]falsenamedfalse

Syntax

Format-SpectreJson [-Data] <Object> [[-Depth] <Int32>] [[-Title] <String>] [[-Border] <String>] [[-Color] <String>] [[-Width] <Int32>] [[-Height] <Int32>] [-Expand] [<CommonParameters>]