You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In PowerShell v6, Convert(To\From)-Json uses Newtonsoft.Json. ConvertTo-Json acknowledges JsonIgnoreAttributes but does not honor JsonPropertyAttributes. have some objects that are decorated with these attributes and serialize differently between ASP.NET and PowerShell. I've had to make a hacked version of ConvertTo-Json to support these attributes. For me, it results in a difference in casing which causes my JavaScript code to fail.
I propose that the JSON cmdlets honor the JsonPropertyAttributes placed on properties.
Which essentially converts the object to a dictionary and striping it of the any useful JSON attributes.
At this point, I'm already convinced the right direction for JSON is to just wrap Newtonsoft and stop using our own logic as well as make some of the newtonsoft features available. This probably needs to be new cmdlets. Because pretty much everything we do at this point is a breaking change in the current cmdlets.
As for fixing this in the current cmdlets... I have some (bad) ideas such as re-inventing the wheel to inspect the attributes on the object properties.. Maybe before we make the object ditcionary, we test the object for Json related attributes and pass the object directly to NewtonSoft... but that has depth issues.
Mark Kraus (@markekraus) I agree this is a super breaking change so I'm not sure the best way to address it and I did make a hacked version of this that bypasses the ProcessCustomObject to produce the dictionary for particular types of objects. This alleviates the depth issue for me but isn't a good fix for PowerShell proper.
I think it would be a little weird to have totally separate cmdlets that do the same thing with different underlying technology but idk if adding parameters to the existing cmdlets is the best option either.
For clarity, the depth issues I was referring to are in regards to to the possible solution of inspecting the object for json attributes.. the question od how deep to inspect and how to detect looping etc..
I'm not fond of having new cmdlets, but the way I see it working is that we'd add the new cmdlets, mark the old ones as deprecated (with warnings), then remove them 3 minor version later and adding the original cmdlets names as aliases to the new ones. In theory, the new cmdlets would "just work" in most cases, but obviously, there would be subtle differences.
Using NewtonSoft directly would be awesome because almost all API C# clients use it to decorate their attributes - in C#/PowerShell they will be PascalCased, but for JSON they usually need to be lowercased. So to support proper interop with APIs honoring JsonPropertyAttribute is crucial.
Mark Kraus (@markekraus) What scenarios we break if we move to Newton serialization?
Will this affect only Convert(To\From)-Json cmdlets?
It would be great if you wrote RFC.
This will allow us to move.
We could enter a new parameter to support backward compatibility and not create new cmdlets.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
Activity
iSazonov commentedon May 10, 2018
Adam Driscoll (@adamdriscoll) Thanks for you report! Please add simple repo steps.
adamdriscoll commentedon May 10, 2018
iSazonov commentedon May 10, 2018
Mark Kraus (@markekraus) Could you please comment the Issue?
markekraus commentedon May 10, 2018
It looks like instead of letting Newtonsoft handle the serialization, we hit this code path
PowerShell/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs
Line 398 in 0f036d9
Which essentially converts the object to a dictionary and striping it of the any useful JSON attributes.
At this point, I'm already convinced the right direction for JSON is to just wrap Newtonsoft and stop using our own logic as well as make some of the newtonsoft features available. This probably needs to be new cmdlets. Because pretty much everything we do at this point is a breaking change in the current cmdlets.
As for fixing this in the current cmdlets... I have some (bad) ideas such as re-inventing the wheel to inspect the attributes on the object properties.. Maybe before we make the object ditcionary, we test the object for Json related attributes and pass the object directly to NewtonSoft... but that has depth issues.
iSazonov commentedon May 11, 2018
Mark Kraus (@markekraus) Thanks!
What does ASP.NET use? Newtonsoft?
adamdriscoll commentedon May 11, 2018
Yeah, it uses NewtonSoft.
adamdriscoll commentedon May 11, 2018
Mark Kraus (@markekraus) I agree this is a super breaking change so I'm not sure the best way to address it and I did make a hacked version of this that bypasses the ProcessCustomObject to produce the dictionary for particular types of objects. This alleviates the depth issue for me but isn't a good fix for PowerShell proper.
I think it would be a little weird to have totally separate cmdlets that do the same thing with different underlying technology but idk if adding parameters to the existing cmdlets is the best option either.
It's a tricky situation, I guess.
markekraus commentedon May 11, 2018
For clarity, the depth issues I was referring to are in regards to to the possible solution of inspecting the object for json attributes.. the question od how deep to inspect and how to detect looping etc..
I'm not fond of having new cmdlets, but the way I see it working is that we'd add the new cmdlets, mark the old ones as deprecated (with warnings), then remove them 3 minor version later and adding the original cmdlets names as aliases to the new ones. In theory, the new cmdlets would "just work" in most cases, but obviously, there would be subtle differences.
felixfbecker commentedon Jun 15, 2018
Using NewtonSoft directly would be awesome because almost all API C# clients use it to decorate their attributes - in C#/PowerShell they will be PascalCased, but for JSON they usually need to be lowercased. So to support proper interop with APIs honoring
JsonPropertyAttributeis crucial.iSazonov commentedon Jun 16, 2018
Mark Kraus (@markekraus) What scenarios we break if we move to Newton serialization?
Will this affect only Convert(To\From)-Json cmdlets?
It would be great if you wrote RFC.
This will allow us to move.
We could enter a new parameter to support backward compatibility and not create new cmdlets.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.