Updates from: 08/07/2021 03:18:36
Service Microsoft Docs article Related commit history on GitHub Change details
Microsoft.PowerShell.Utility Convertto Json (5.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/5.1/Microsoft.PowerShell.Utility/ConvertTo-Json.md
Title: ConvertTo-Json
--- # ConvertTo-Json
-## SYNOPSIS
+## Synopsis
Converts an object to a JSON-formatted string.
-## SYNTAX
+## Syntax
``` ConvertTo-Json [-InputObject] <Object> [-Depth <Int32>] [-Compress] [<CommonParameters>] ```
-## DESCRIPTION
+## Description
The `ConvertTo-Json` cmdlet converts any .NET object to a string in JavaScript Object Notation (JSON) format. The properties are converted to field names, the field values are converted to
web-based apps.
This cmdlet was introduced in Windows PowerShell 3.0.
-## EXAMPLES
+## Examples
### Example 1
Year : 2018
This example shows how to use the `ConvertTo-Json` and `ConvertFrom-Json` cmdlets to convert an object to a JSON string and a JSON object.
-## PARAMETERS
+## Parameters
### -Compress
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
-WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](../Microsoft.PowerShell.Core/About/about_CommonParameters.md).
-## INPUTS
+## Inputs
### System.Object You can pipe any object to `ConvertTo-Json`.
-## OUTPUTS
+## Outputs
### System.String
-## NOTES
+## Notes
The `ConvertTo-Json` cmdlet is implemented using the [JavaScriptSerializer class](/dotnet/api/system.web.script.serialization.javascriptserializer).
-## RELATED LINKS
+## Related links
[An Introduction to JavaScript Object Notation (JSON) in JavaScript and .NET](/previous-versions/dotnet/articles/bb299886(v=msdn.10))
Microsoft.PowerShell.Utility Convertto Json (7.0) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.0/Microsoft.PowerShell.Utility/ConvertTo-Json.md
Title: ConvertTo-Json
--- # ConvertTo-Json
-## SYNOPSIS
+## Synopsis
Converts an object to a JSON-formatted string.
-## SYNTAX
+## Syntax
``` ConvertTo-Json [-InputObject] <Object> [-Depth <Int32>] [-Compress]
ConvertTo-Json [-InputObject] <Object> [-Depth <Int32>] [-Compress]
[<CommonParameters>] ```
-## DESCRIPTION
+## Description
The `ConvertTo-Json` cmdlet converts any .NET object to a string in JavaScript Object Notation (JSON) format. The properties are converted to field names, the field values are converted to
web-based apps.
This cmdlet was introduced in Windows PowerShell 3.0.
-## EXAMPLES
+## Examples
### Example 1
Year : 2018
This example shows how to use the `ConvertTo-Json` and `ConvertFrom-Json` cmdlets to convert an object to a JSON string and a JSON object.
-## PARAMETERS
+## Parameters
### -AsArray
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
-WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](../Microsoft.PowerShell.Core/About/about_CommonParameters.md).
-## INPUTS
+## Inputs
### System.Object You can pipe any object to `ConvertTo-Json`.
-## OUTPUTS
+## Outputs
### System.String
-## NOTES
+## Notes
The `ConvertTo-Json` cmdlet is implemented using [Newtonsoft Json.NET](https://www.newtonsoft.com/json).
-## RELATED LINKS
+## Related links
[An Introduction to JavaScript Object Notation (JSON) in JavaScript and .NET](/previous-versions/dotnet/articles/bb299886(v=msdn.10))
Microsoft.PowerShell.Utility Convertto Json (7.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.1/Microsoft.PowerShell.Utility/ConvertTo-Json.md
Title: ConvertTo-Json
--- # ConvertTo-Json
-## SYNOPSIS
+## Synopsis
Converts an object to a JSON-formatted string.
-## SYNTAX
+## Syntax
``` ConvertTo-Json [-InputObject] <Object> [-Depth <Int32>] [-Compress]
ConvertTo-Json [-InputObject] <Object> [-Depth <Int32>] [-Compress]
[<CommonParameters>] ```
-## DESCRIPTION
+## Description
The `ConvertTo-Json` cmdlet converts any .NET object to a string in JavaScript Object Notation (JSON) format. The properties are converted to field names, the field values are converted to
the depth specified for the command. This prevents unwanted data loss when conve
This cmdlet was introduced in Windows PowerShell 3.0.
-## EXAMPLES
+## Examples
### Example 1
Year : 2018
This example shows how to use the `ConvertTo-Json` and `ConvertFrom-Json` cmdlets to convert an object to a JSON string and a JSON object.
-## PARAMETERS
+## Parameters
### -AsArray
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
-WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](../Microsoft.PowerShell.Core/About/about_CommonParameters.md).
-## INPUTS
+## Inputs
### System.Object You can pipe any object to `ConvertTo-Json`.
-## OUTPUTS
+## Outputs
### System.String
-## NOTES
+## Notes
The `ConvertTo-Json` cmdlet is implemented using [Newtonsoft Json.NET](https://www.newtonsoft.com/json).
-## RELATED LINKS
+## Related links
[An Introduction to JavaScript Object Notation (JSON) in JavaScript and .NET](/previous-versions/dotnet/articles/bb299886(v=msdn.10))
Microsoft.PowerShell.Utility Convertto Json (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Utility/ConvertTo-Json.md
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Utility Previously updated : 05/04/2021 Last updated : 08/05/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/convertto-json?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 Title: ConvertTo-Json --- # ConvertTo-Json
-## SYNOPSIS
+## Synopsis
Converts an object to a JSON-formatted string.
-## SYNTAX
+## Syntax
``` ConvertTo-Json [-InputObject] <Object> [-Depth <Int32>] [-Compress]
ConvertTo-Json [-InputObject] <Object> [-Depth <Int32>] [-Compress]
[<CommonParameters>] ```
-## DESCRIPTION
+## Description
The `ConvertTo-Json` cmdlet converts any .NET object to a string in JavaScript Object Notation (JSON) format. The properties are converted to field names, the field values are converted to property values, and the methods are removed.
+> [!NOTE]
+> As of PowerShell 7.2, Extended Type System properties of **DateTime** and
+> **String** objects are no longer serialized and only the simple object is
+> converted to JSON format
+ You can then use the `ConvertFrom-Json` cmdlet to convert a JSON-formatted string to a JSON object, which is easily managed in PowerShell.
the depth specified for the command. This prevents unwanted data loss when conve
This cmdlet was introduced in Windows PowerShell 3.0.
-## EXAMPLES
+## Examples
### Example 1
Get-Date | ConvertTo-Json; Get-Date | ConvertTo-Json -AsArray
``` ```Output
-{
- "value": "2018-10-12T23:07:18.8450248-05:00",
- "DisplayHint": 2,
- "DateTime": "October 12, 2018 11:07:18 PM"
-}
+"2021-08-05T16:13:05.6394416-07:00"
[
- {
- "value": "2018-10-12T23:07:18.8480668-05:00",
- "DisplayHint": 2,
- "DateTime": "October 12, 2018 11:07:18 PM"
- }
+ "2021-08-05T16:13:05.6421709-07:00"
] ```
Year : 2018
This example shows how to use the `ConvertTo-Json` and `ConvertFrom-Json` cmdlets to convert an object to a JSON string and a JSON object.
-## PARAMETERS
+## Parameters
### -AsArray
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
-WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](../Microsoft.PowerShell.Core/About/about_CommonParameters.md).
-## INPUTS
+## Inputs
### System.Object You can pipe any object to `ConvertTo-Json`.
-## OUTPUTS
+## Outputs
### System.String
-## NOTES
+## Notes
The `ConvertTo-Json` cmdlet is implemented using [Newtonsoft Json.NET](https://www.newtonsoft.com/json).
-## RELATED LINKS
+## Related links
[An Introduction to JavaScript Object Notation (JSON) in JavaScript and .NET](/previous-versions/dotnet/articles/bb299886(v=msdn.10))
lang-spec Chapter 05 https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/lang-spec/chapter-05.md
been defined, use the [Test-Path](xref:Microsoft.PowerShell.Management.Test-Path
## 5.1 Writable location A *writable location* is an expression that designates a resource to which a command has both read
-and write access. A writable location may be a variable (§5), an array element (§9), an associated
-value in a Hashtable accessed via a subscript (§10), a property ([§7.1.2][§7.1.2]), or storage managed by
+and write access. A writable location may be a variable ([§5][§5]), an array element ([§9][§9]), an associated
+value in a Hashtable accessed via a subscript ([§10][§10]), a property ([§7.1.2][§7.1.2]), or storage managed by
a provider ([§3.1][§3.1]). ## 5.2 Variable categories
An array can be created via a unary comma operator ([§7.2.1][§7.2.1]), *sub-ex
Memory for creating and deleting arrays is managed by the host environment and the garbage collection system.
-Arrays and array elements are discussed in [§9.][§9.]
+Arrays and array elements are discussed in [§9][§9].
### 5.2.4 Hashtable key/value pairs
via the `[]` operator ([§7.1.4.3][§7.1.4.3]).
Memory for creating and deleting Hashtables is managed by the host environment and the garbage collection system.
-Hashtables are discussed in §10.
+Hashtables are discussed in [§10][§10].
### 5.2.5 Parameters
namespace **Function:** ([§2.3.2][§2.3.2], [§3.1][§3.1]) is constrained impl
[§4.3.2]: chapter-04.md#432-arrays [§4.3.3]: chapter-04.md#433-hashtables [§4.3.8]: chapter-04.md#438-the-math-type
+[§5]: chapter-05.md#5-variables
[§5.2.6]: chapter-05.md#526-ordinary-variables [§5.2.7]: chapter-05.md#527-variables-on-provider-drives [§5.3]: chapter-05.md#53-constrained-variables
namespace **Function:** ([§2.3.2][§2.3.2], [§3.1][§3.1]) is constrained impl
[§7.4]: chapter-07.md#74-range-operator [§8.10]: chapter-08.md#810-function-definitions [§8.4.4]: chapter-08.md#844-the-foreach-statement
-[§9.]: chapter-09.md#9-arrays
+[§9]: chapter-09.md#9-arrays
+[§10]: chapter-10.md#10-hashtables