Skip to content

Format-Json

SYNOPSIS

Formats a JSON string or PowerShell object.

SYNTAX

FromString (Default)

Format-Json -JsonString <string> [-Compact] [-IndentationType <string>] [-IndentationSize <ushort>]
 [<CommonParameters>]

FromObject

Format-Json -InputObject <psobject> [-Compact] [-IndentationType <string>]
 [-IndentationSize <ushort>] [<CommonParameters>]

ALIASES

This cmdlet has the following aliases, {{Insert list of aliases}}

DESCRIPTION

Converts raw JSON strings or PowerShell objects into formatted JSON. Supports pretty-printing with configurable indentation or compact output.

EXAMPLES

EXAMPLE 1

Format-Json -JsonString '{"a":1,"b":{"c":2}}' -IndentationType Spaces -IndentationSize 2

EXAMPLE 2

$obj = @{ user = 'Marius'; roles = @('admin','dev') } Format-Json -InputObject $obj -IndentationType Tabs -IndentationSize 1

EXAMPLE 3

Format-Json -JsonString '{"a":1,"b":{"c":2}}' -Compact

PARAMETERS

-Compact

Produce compact (minified) output.

Type: System.Management.Automation.SwitchParameter
DefaultValue: False
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: FromObject
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
- Name: FromString
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-IndentationSize

Number of spaces or tabs per indentation level. Only used if not compacting.

Type: System.UInt16
DefaultValue: 2
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: FromObject
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
- Name: FromString
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-IndentationType

Indentation type: 'Spaces' or 'Tabs'.

Type: System.String
DefaultValue: Spaces
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: FromObject
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
- Name: FromString
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-InputObject

PowerShell object to convert and format as JSON.

Type: System.Management.Automation.PSObject
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: FromObject
  Position: Named
  IsRequired: true
  ValueFromPipeline: true
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-JsonString

JSON string to format.

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: FromString
  Position: Named
  IsRequired: true
  ValueFromPipeline: true
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

System.String

{{ Fill in the Description }}

System.Management.Automation.PSObject

{{ Fill in the Description }}

OUTPUTS

NOTES