Types/OpenPackage.Part/WriteJsonL.ps1
|
<# .SYNOPSIS Writes Part Content as Json Lines .DESCRIPTION Writes Open Package Part Content as Json Lines #> [Reflection.AssemblyMetadata( 'FilePattern', '\.(?>cast|jsonl|jsonnd)?$' )] param( # The object to write. [Alias('Input','Content','Text')] [PSObject] $InputObject, <# Any options used to write the object Supported Options: |Option|Description| |-|-| |Depth|The serialization depth| |Encoding|The text encoding| |Stream|Optional destination stream| #> [Collections.IDictionary] $Option = [Ordered]@{} ) # If this object does not have a write text method, return. if (-not $this.WriteText) { throw 'No `.WriteText()`'; return } # If no depth was set, if (-not $option.Depth) { # use double the format enumeration limit (by default, 8) $option.Depth = $FormatEnumerationLimit * 2 } # If we have a .Package and .PartUri property if ($InputObject.Package -is [IO.Packaging.Package] -and $InputObject.PartUri -is [uri]) { # avoid putting them in the object $text = @(foreach ($in in $InputObject | Select-Object -Property * -ExcludeProperty 'Package', 'PartUri') { ConvertTo-Json -InputObject $in -Depth $Option.Depth -Compress }) -join [Environment]::NewLine } else { # Convert any other objects to json. $text = @(foreach ($in in $InputObject) { ConvertTo-Json -InputObject $in -Depth $Option.Depth -Compress }) -join [Environment]::NewLine } # Then, write the text $this.WriteText($text, $Option) |