Skip to content

ConvertFrom-Json does not respect -ErrorAction #2860

@alastairs

Description

@alastairs

Steps to reproduce

Run the following expressions:

"some invalid JSON string" | ConvertFrom-Json -ErrorAction Ignore
"some invalid JSON string" | ConvertFrom-Json -ErrorAction SilentlyContinue

Expected behavior

Both expressions write no error to the console, and return either $null or the empty string.

Actual behavior

The expressions write an error to the console and throw the following exception:

ConvertFrom-Json : Invalid JSON primitive: some invalid JSON string.
At line:1 char:12
+ "some invalid JSON string" | ConvertFrom-Json -ErrorAction Ignore
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [ConvertFrom-Json], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.14393.206
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.206
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Metadata

Metadata

Assignees

Labels

Committee-ReviewedPS-Committee has reviewed this and made a decisionResolution-By DesignThe reported behavior is by design.WG-Cmdletsgeneral cmdlet issues

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions