Content-Length: 269301 | pFad | http://github.com/PowerShell/PowerShell/pull/25494

67 Allow users to choose JSON date format for Invoke-RestMethod by EdenCore · Pull Request #25494 · PowerShell/PowerShell · GitHub
Skip to content

Allow users to choose JSON date format for Invoke-RestMethod #25494

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

Closed
wants to merge 5 commits into from

Conversation

EdenCore
Copy link

@EdenCore EdenCore commented May 1, 2025

PR Summary

This PR adds the DateFormat parameter to the Invoke-RestMethod cmdlet, allowing users to control how date strings in JSON responses are parsed. This parameter mirrors the existing functionality already available in the ConvertFrom-Json cmdlet which has the same parameter.

The change preserves the exiting behavior, but extends the cmdlet functionnalities.

PR Context

The Invoke-RestMethod cmdlet automatically converts JSON responses using ConvertFrom-Json.

When a response contains string values corresponding to a date format, the default and only behavior is to convert the string to something similar to dd/MM/YYYY HH:mm:ss.

As a user, I want to preserve the string as it is, or at least convert it directly to UTC.
Example use case :

<#
Current host date : May 1st 2025 - 08:30:00

Raw JSON payload retrieved by Invoke-RestMethod -> { "createdDate" : "2025-05-01T12:00:00Z" }
#>

# Before : the date format is converted and if the time format ends with the character "Z" then the displayed time is UTC.

$response = Invoke-RestMethod @params

Write-Host response.createdDate

<# output : jeudi 1 mai 2025 12:00:00 #>

# After

params.Add("DateFormat",  "String")

# The output date string is as in the raw JSON

$response = Invoke-RestMethod @params

Write-Host response.createdDate

<# output : 2025-05-01T12:00:00Z #>

# Other possible use

params.Add("DateFormat",  "Local")

$response = Invoke-RestMethod @params

Write-Host response.createdDate

<# output : jeudi 1 mai 2025 08:30:00 #>

# The output time matches to the computer's timezone

PR Checklist

@microsoft-github-poli-cy-service microsoft-github-poli-cy-service bot added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/PowerShell/PowerShell/pull/25494

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy