Function/Get-ContainerDefinitionJsonSerializerOptions.Function.psm1
using namespace System.Text.Json; using namespace System.Text.Json.Serialization; ## Get-ContainerDefinitionJsonOptions Function. function Get-ContainerDefinitionJsonSerializerOptions { <# .NAME Get-ContainerDefinitionJsonSerializerOptions .SYNOPSIS Retrieves JSON serialization options for container definitions. .SYNTAX Get-ContainerDefinitionJsonOptions [-PrettyPrint <Boolean>] .DESCRIPTION This function returns a JsonSerializerOptions object configured for serializing and deserializing container definitions, with options for pretty-printing the output. .PARAMETERS -PrettyPrint If true, the JSON output will be formatted with indentation for readability. If false, the JSON will be compact without extra whitespace. Required? false Default $true .OUTPUTS JsonSerializerOptions The configured JSON serialization options. .EXAMPLE [JsonSerializerOptions] $jsonOptions = ` Get-ContainerDefinitionJsonOptions [-PrettyPrint $true]; #> param ( ## Pretty Print Parameter. [Parameter(Mandatory = $false, Position = 0)] [Boolean] $prettyPrint = $true ); ## Define our JSON serialization options. [JsonSerializerOptions] $jsonOptions = [JsonSerializerOptions]::new(); ## Allow trailing commas in the JSON file. $jsonOptions.AllowTrailingCommas = $true; ## Use case-insensitivity when reading property names. $jsonOptions.PropertyNameCaseInsensitive = $true; ## Ignore comments in the JSON file. $jsonOptions.ReadCommentHandling = [JsonCommentHandling]::Skip; ## Check the pretty print flag. if ($prettyPrint) { ## Write the JSON with indented formatting. $jsonOptions.WriteIndented = $true; } ## We'll want to serialize enums as strings. $jsonOptions.Converters.Add([JsonStringEnumConverter]::new()); ## We're done, return the JSON options. return $jsonOptions; }; |