Skip to content

Commit

Permalink
feat: Out-JSON ( Fixes #727 )
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed Mar 9, 2024
1 parent b0267b3 commit a50a7a7
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Commands/JSON/Out-JSON.ps.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[ValidatePattern("JSON")]
param()

function Out-JSON {
<#
.SYNOPSIS
Outputs objects as JSON
.DESCRIPTION
Outputs objects in JSON.
#>
[CmdletBinding(PositionalBinding=$false)]
[Alias('text.json.out')]
param(
# The input object. This will form the majority of the JSON.
[vfp()]
[PSObject]
$InputObject,

# Any arguments. These will be appended to the input.
[Parameter(ValueFromRemainingArguments=$true)]
[PSObject[]]
$ArgumentList,

# The depth of the JSON. By default, this is the FormatEnumerationLimit.
[int]
$Depth = $FormatEnumerationLimit
)

$inputAndArguments = @( $input ) + $ArgumentList
if (-not $depth) {
$depth = if ($FormatEnumerationLimit) {
$FormatEnumerationLimit
} else {
4
}
}
if ($inputAndArguments.Length -eq 1) {
ConvertTo-Json -InputObject $inputAndArguments[0] -Depth $Depth
} else {
$inputAndArguments | ConvertTo-Json -Depth $Depth
}
}

0 comments on commit a50a7a7

Please sign in to comment.