Export-Json¶
SYNOPSIS¶
Exports JSON data to a file.
SYNTAX¶
FromObject (Default)¶
Export-Json -InputObject <psobject> -Path <string> [-Compact] [-IndentationType <string>]
[-IndentationSize <ushort>] [-Depth <int>] [-Force] [-Encoding <string>] [-PassThru] [-WhatIf]
[-Confirm] [<CommonParameters>]
FromString¶
Export-Json -JsonString <string> -Path <string> [-Compact] [-IndentationType <string>]
[-IndentationSize <ushort>] [-Depth <int>] [-Force] [-Encoding <string>] [-PassThru] [-WhatIf]
[-Confirm] [<CommonParameters>]
ALIASES¶
This cmdlet has the following aliases, {{Insert list of aliases}}
DESCRIPTION¶
Converts PowerShell objects to JSON format and writes them to one or more files. Supports various formatting options including indentation types, sizes, and compact output. Can accept both PowerShell objects and JSON strings as input.
EXAMPLES¶
EXAMPLE 1¶
Export-Json -InputObject $myObject -Path 'output.json'
Exports a PowerShell object to output.json with default formatting.
EXAMPLE 2¶
Export-Json -InputObject $data -Path 'config.json' -IndentationType Spaces -IndentationSize 2
Exports data to config.json with 2-space indentation.
EXAMPLE 3¶
Export-Json -JsonString $jsonText -Path 'data.json' -Compact
Exports a JSON string to data.json in compact format.
EXAMPLE 4¶
$objects | Export-Json -Path 'output.json'
Exports multiple objects to the same file via pipeline (last object overwrites).
EXAMPLE 5¶
Export-Json -InputObject $config -Path 'settings.json' -IndentationType Tabs -Force
Exports configuration to settings.json with tab indentation, overwriting if it exists.
EXAMPLE 6¶
$file = Export-Json -InputObject $data -Path 'output.json' -PassThru
Exports data and returns the file object for further processing.
PARAMETERS¶
-Compact¶
Produce compact (minified) output.
Type: System.Management.Automation.SwitchParameter
DefaultValue: False
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
-Confirm¶
Prompts you for confirmation before running the cmdlet.
Type: System.Management.Automation.SwitchParameter
DefaultValue: ''
SupportsWildcards: false
Aliases:
- cf
ParameterSets:
- Name: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
-Depth¶
The maximum depth to serialize nested objects.
Type: System.Int32
DefaultValue: 2
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
-Encoding¶
Text encoding for the output file.
Type: System.String
DefaultValue: UTF8
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
-Force¶
Overwrite existing files without prompting.
Type: System.Management.Automation.SwitchParameter
DefaultValue: False
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
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: (All)
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: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
-InputObject¶
PowerShell object to convert and export 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 export to file.
Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: FromString
Position: Named
IsRequired: true
ValueFromPipeline: true
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
-PassThru¶
Return the file object after export.
Type: System.Management.Automation.SwitchParameter
DefaultValue: False
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
-Path¶
The path to the output JSON file.
Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: Named
IsRequired: true
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
-WhatIf¶
Runs the command in a mode that only reports what would happen without performing the actions.
Type: System.Management.Automation.SwitchParameter
DefaultValue: ''
SupportsWildcards: false
Aliases:
- wi
ParameterSets:
- Name: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
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.Management.Automation.PSObject¶
{{ Fill in the Description }}
System.String¶
{{ Fill in the Description }}