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.
Terminal window
$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
Example 2
This example demonstrates how to display json string data using Format-SpectreJson.
Terminal window
$jsonString=@{
Name='Alice'
Age=30
Skills=@('PowerShell','Spectre.Console')
} |ConvertTo-Json
# Display the JSON string using Format-SpectreJson
$jsonString|Format-SpectreJson
Example 3
This example demonstrates how to display the contents of one or more JSON files directly using Format-SpectreJson.
Create temporary JSON files for demonstration, use a random execution ID to avoid reading random json files from the temp directory.