- Notifications
You must be signed in to change notification settings - Fork8.1k
Description
I'd like to propose an additional parameter for the ConvertTo-Json cmdlet that specifies the caller would like the cmdlet to ignore properties of the InputObject that cannot be converted to JSON successfully. Currently, the behavior of the cmdlet is to throw an exception with a message similar to the following
"ConvertTo-Json : The type 'System.Collections.ListDictionaryInternal' is not supported for serialization or "deserialization of a dictionary. Keys must be strings.
My proposal is that if the-SkipIncompatibleProperties (parm name feedback appreciated :-) ) parameter is specified, then the cmdlet would silently skip over these properties and not throw any exceptions.
I've been frustrated by this error several times in my scripting in situations where I don't really care about the particular property that triggered the error; I would just like a quick and easy serialized representation of the object. In the most recent instance, I needed a way to record exception info in a VARCHAR column in SQL Server. The property of the System.Exception that triggered this error was the "Data" field which I didn't really care about, but it prevented me from easily using the cmdlet to serialize the exception object.
As an aside, it looks like there is a proposal by@KirkMunro tomove the JSON cmdlets to their own module. I understand it may make sense to wait on this feature until the module split occurs.