Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoke-RestMethod should have an -AsHashTable switch #19378

Open
iRon7 opened this issue Mar 21, 2023 · 7 comments
Open

Invoke-RestMethod should have an -AsHashTable switch #19378

iRon7 opened this issue Mar 21, 2023 · 7 comments
Labels
Issue-Enhancement the issue is more of a feature request than a bug WG-Cmdlets general cmdlet issues

Comments

@iRon7
Copy link

iRon7 commented Mar 21, 2023

Summary of the new feature / enhancement

For the same reason as ConvertFrom-Json has an -AsHashTable parameter (see: #3159), Invoke-RestMethod should have an -AsHashTable switch to convert to a HashTable (or an OrderedHashTable)

See e.g.: powershell add key value to the json

Proposed technical implementation details (optional)

No response

@iRon7 iRon7 added Issue-Enhancement the issue is more of a feature request than a bug Needs-Triage The issue is new and needs to be triaged by a work group. labels Mar 21, 2023
@iRon7 iRon7 changed the title Invoke-RestMethod should have an -AsHashTable switch Invoke-RestMethod should have a -AsHashTable switch Mar 21, 2023
@iRon7 iRon7 changed the title Invoke-RestMethod should have a -AsHashTable switch Invoke-RestMethod should have an -AsHashTable switch Mar 21, 2023
@jhoneill jhoneill added WG-Cmdlets general cmdlet issues and removed Needs-Triage The issue is new and needs to be triaged by a work group. labels Mar 21, 2023
@jhoneill
Copy link

This would be useful. Somewhere - I can't remember where - I had to write code to convert the object returned back to hash table.

@CarloToso
Copy link
Contributor

Related #7880

@BrucePay
Copy link
Collaborator

What happens when the payload is NOT JSON?

@iRon7
Copy link
Author

iRon7 commented Mar 22, 2023

@BrucePay,

What happens when the payload is NOT JSON?

I guess a simple warning as:

WARNING: Cannot convert, or deserialize, the returned content into a HashTable

and returning the content "as is", will be sufficient.

In general, I don't see any issue when a potential -AsHashTable switch is given and it is able to convert it into a [PSCustomObject] to convert it into a [OrderedHashTable] instead.
Meaning:

PowerShell formats the response based to the data type. For an RSS or ATOM feed, PowerShell returns the Item or
Entry XML nodes. For JavaScript Object Notation (JSON) or XML, PowerShell converts, or deserializes, the content
into [PSCustomObject] objects or an [OrderedHashTable] in case the -AsHashTable switch is set.

@SteveL-MSFT
Copy link
Member

XML could be converted to a hashtable, but I suspect no one actually wants that. Perhaps in this case such a switch needs to be more explicit like -JsonAsHashtable where it's documented that it's a no-op if not JSON?

@microsoft-github-policy-service microsoft-github-policy-service bot added Resolution-No Activity Issue has had no activity for 6 months or more labels Nov 15, 2023
@iRon7
Copy link
Author

iRon7 commented Nov 15, 2023

Please either mark this issue with something like Resolution-Declined or put it on a kind of wishlist "Issue we would like to prioritize, but we can't commit we will get to it yet"

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Resolution-No Activity Issue has had no activity for 6 months or more label Nov 15, 2023
@nkasco
Copy link

nkasco commented Mar 26, 2024

XML could be converted to a hashtable, but I suspect no one actually wants that. Perhaps in this case such a switch needs to be more explicit like -JsonAsHashtable where it's documented that it's a no-op if not JSON?

I'm good with this. Just ran into this and while I can just pipe the result into ConvertFrom-JSON -AsHashTable, would be clean to do all upfront.

Is there a performance or data hit if you use it when you don't need to? (like it there aren't duplicate keys with different spellings?)
@SteveL-MSFT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement the issue is more of a feature request than a bug WG-Cmdlets general cmdlet issues
Projects
None yet
Development

No branches or pull requests

6 participants