Skip to content

Commit ed2e99c

Browse files
jborean93sdwheeler
authored andcommitted
Document PSSerializeJSONLongEnumAsNumber
Documents the new experiemental feature PSSerializeJSONLongEnumAsNumber that aligns the serialization behaviour of enums based on long/ulong with the other base types.
1 parent 6e6f949 commit ed2e99c

File tree

1 file changed

+50
-16
lines changed

1 file changed

+50
-16
lines changed

reference/docs-conceptual/learn/experimental-features.md

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
description: Lists the currently available experimental features and how to use them.
3-
ms.date: 08/28/2024
3+
ms.date: 09/24/2024
44
title: Using Experimental Features in PowerShell
55
---
66
# Using Experimental Features in PowerShell
@@ -15,14 +15,14 @@ breaking changes.
1515
> [!CAUTION]
1616
> Experimental features aren't intended to be used in production since the changes are allowed to be
1717
> breaking. Experimental features aren't officially supported. However, we appreciate any feedback
18-
> and bug reports. You can file issues in the [GitHub source repository][25].
18+
> and bug reports. You can file issues in the [GitHub source repository][26].
1919
2020
For more information about enabling or disabling these features, see
2121
[about_Experimental_Features][06].
2222

2323
## Experimental feature lifecycle
2424

25-
The [Get-ExperimentalFeature][29] cmdlet returns all experimental features available to PowerShell.
25+
The [Get-ExperimentalFeature][30] cmdlet returns all experimental features available to PowerShell.
2626
Experimental features can come from modules or the PowerShell engine. Module-based experimental
2727
features are only available after you import the module. In the following example, the
2828
**PSDesiredStateConfiguration** isn't loaded, so the `PSDesiredStateConfiguration.InvokeDscResource`
@@ -40,10 +40,11 @@ PSCommandWithArgs False PSEngine Enable `-CommandWithArgs` para
4040
PSFeedbackProvider True PSEngine Replace the hard-coded suggestion framework with …
4141
PSLoadAssemblyFromNativeCode False PSEngine Expose an API to allow assembly loading from nati…
4242
PSModuleAutoLoadSkipOfflineFiles True PSEngine Module discovery will skip over files that are ma…
43+
PSSerializeJSONLongEnumAsNumber True PSEngine Serialize enums based on long or ulong as an nume…
4344
PSSubsystemPluginModel True PSEngine A plugin model for registering and un-registering…
4445
```
4546

46-
Use the [Enable-ExperimentalFeature][28] and [Disable-ExperimentalFeature][27] cmdlets to enable or
47+
Use the [Enable-ExperimentalFeature][29] and [Disable-ExperimentalFeature][28] cmdlets to enable or
4748
disable a feature. You must start a new PowerShell session for this change to be in effect. Run the
4849
following command to enable the `PSCommandNotFoundSuggestion` feature:
4950

@@ -96,6 +97,7 @@ Legend
9697
| [PSCommandWithArgs][11] | | ![Experimental][02] | ![Experimental][02] |
9798
| [PSNativeWindowsTildeExpansion][22] | | | ![Experimental][02] |
9899
| [PSRedirectToVariable][24] | | | ![Experimental][02] |
100+
| [PSSerializeJSONLongEnumAsNumber][25] | | | ![Experimental][02] |
99101

100102
### PSAnsiRenderingFileInfo
101103

@@ -213,7 +215,7 @@ a native executable.
213215
> The new behavior is a **breaking change** from current behavior. This may break scripts and
214216
> automation that work around the various issues when invoking native applications. Historically,
215217
> quotes must be escaped and it isn't possible to provide empty arguments to a native application.
216-
> Use the [stop-parsing token][08] (`--%`) or the [`Start-Process`][31] cmdlet to sidestep native
218+
> Use the [stop-parsing token][08] (`--%`) or the [`Start-Process`][32] cmdlet to sidestep native
217219
> argument passing when needed.
218220
219221
This feature adds a new `$PSNativeCommandArgumentPassing` preference variable that controls this
@@ -245,7 +247,7 @@ and non-Windows platforms is `Standard`.
245247

246248
> [!NOTE]
247249
> The following examples use the `TestExe.exe` tool. You can build `TestExe` from the source code.
248-
> See [TestExe][26] in the PowerShell source repository.
250+
> See [TestExe][27] in the PowerShell source repository.
249251
250252
New behaviors made available by this change:
251253

@@ -272,7 +274,7 @@ New behaviors made available by this change:
272274
For more examples of the new behavior, see [about_Parsing][07].
273275

274276
PowerShell 7.3 also added the ability to trace parameter binding for native commands. For more
275-
information, see [Trace-Command][32].
277+
information, see [Trace-Command][34].
276278

277279
### PSNativeCommandErrorActionPreference
278280

@@ -365,7 +367,7 @@ the PSReadLine module to provide custom prediction plugins. In future, **Job**,
365367
**CommandCompleter**, **Remoting** and other components could be separated into subsystem assemblies
366368
outside of `System.Management.Automation.dll`.
367369

368-
The experimental feature includes a new cmdlet, [Get-PSSubsystem][30]. This cmdlet is only available
370+
The experimental feature includes a new cmdlet, [Get-PSSubsystem][31]. This cmdlet is only available
369371
when the feature is enabled. This cmdlet returns information about the subsystems that are available
370372
on the system.
371373

@@ -392,6 +394,36 @@ This feature only applies to Windows. On non-Windows platforms, tilde expansion
392394

393395
This feature was added in PowerShell 7.5-preview.2.
394396

397+
### PSSerializeJSONLongEnumAsNumber
398+
399+
This feature enables the cmdlet [ConvertTo-Json][33] to serialize any enum values based on
400+
`Int64/long` or `UInt64/ulong` as a numeric value rather than the string representation of that enum
401+
value. This aligns the behavior of enum serialization with other enum base types where the cmdlet
402+
serializes enums as their numeric value. Use the **EnumsAsStrings** parameter to serialize as the
403+
string representation.
404+
405+
For example:
406+
407+
```powershell
408+
# PSSerializeJSONLongEnumAsNumber disabled
409+
@{
410+
Key = [System.Management.Automation.Tracing.PowerShellTraceKeywords]::Cmdlets
411+
} | ConvertTo-Json
412+
# { "Key": "Cmdlets" }
413+
414+
# PSSerializeJSONLongEnumAsNumber enabled
415+
@{
416+
Key = [System.Management.Automation.Tracing.PowerShellTraceKeywords]::Cmdlets
417+
} | ConvertTo-Json
418+
# { "Key": 32 }
419+
420+
# -EnumsAsStrings to revert back to the old behaviour
421+
@{
422+
Key = [System.Management.Automation.Tracing.PowerShellTraceKeywords]::Cmdlets
423+
} | ConvertTo-Json -EnumsAsStrings
424+
# { "Key": "Cmdlets" }
425+
```
426+
395427
<!-- link references -->
396428
[01]: ../../media/shared/check-mark-button-2705.svg
397429
[02]: ../../media/shared/construction-sign-1f6a7.svg
@@ -414,11 +446,13 @@ This feature was added in PowerShell 7.5-preview.2.
414446
[22]: #psnativewindowstildeexpansion
415447
[23]: #pssubsystempluginmodel
416448
[24]: #psredirecttovariable
417-
[25]: https://github.com/PowerShell/PowerShell/issues/new/choose
418-
[26]: https://github.com/PowerShell/PowerShell/tree/master/test/tools/TestExe
419-
[27]: xref:Microsoft.PowerShell.Core.Disable-ExperimentalFeature
420-
[28]: xref:Microsoft.PowerShell.Core.Enable-ExperimentalFeature
421-
[29]: xref:Microsoft.PowerShell.Core.Get-ExperimentalFeature
422-
[30]: xref:Microsoft.PowerShell.Core.Get-PSSubsystem
423-
[31]: xref:Microsoft.PowerShell.Management.Start-Process
424-
[32]: xref:Microsoft.PowerShell.Utility.Trace-Command
449+
[25]: #psserializejsonlongenumasnumber
450+
[26]: https://github.com/PowerShell/PowerShell/issues/new/choose
451+
[27]: https://github.com/PowerShell/PowerShell/tree/master/test/tools/TestExe
452+
[28]: xref:Microsoft.PowerShell.Core.Disable-ExperimentalFeature
453+
[29]: xref:Microsoft.PowerShell.Core.Enable-ExperimentalFeature
454+
[30]: xref:Microsoft.PowerShell.Core.Get-ExperimentalFeature
455+
[31]: xref:Microsoft.PowerShell.Core.Get-PSSubsystem
456+
[32]: xref:Microsoft.PowerShell.Management.Start-Process
457+
[33]: xref:Microsoft.PowerShell.Utility.ConvertTo-Json
458+
[34]: xref:Microsoft.PowerShell.Utility.Trace-Command

0 commit comments

Comments
 (0)