[英]JSON Prettifier Using Azure Function w/ PowerShell and HTTP Trigger
Thought this would be pretty simple, but alas, I can't figure it out. 以为这很简单,但是a,我无法弄清楚。 It appears that PowerShell will prettify JSON with a single cmdlet .
看来PowerShell将使用单个cmdlet来美化JSON 。
Goal : Prettify JSON using a PowerShell Azure Function app 目标 :使用PowerShell Azure Function应用美化JSON
ConvertToJson
cmdlet to prettify?) and outputs the file back to Flow ConvertToJson
cmdlet进行美化?)并将文件输出回Flow Questions : 问题 :
I have taken below serialize string 我在下面采取了序列化字符串
'{ "baz": "quuz", "cow": [ "moo", "cud" ], "foo": "bar" }'
which was mentioned in Prettify json in powershell 3 在Powershell 3的Prettify json中提到过
Here is my function which i used with HttpPost and send the request: 这是我与HttpPost一起使用并发送请求的函数:
using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
# Write to the Azure Functions log stream.
Write-Host "PowerShell HTTP trigger function processed a request."
# Interact with query parameters or the body of the request.
$name = $Request.Query.baz
if (-not $name) {
$name = $Request.Body.baz
}
if ($name) {
$status = [HttpStatusCode]::OK
$body = "Hello $name"
}
else {
$status = [HttpStatusCode]::BadRequest
$body = "Please pass a name on the query string or in the request body."
}
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = $status
Body = $body
})
and below you can see , i am able to read it from the string which i posted. 在下面,您可以看到,我可以从我发布的字符串中读取它。
You can use ConvertFrom-Json
to convert it but i wondering if you even need it as you can access it by doing below: 您可以使用
ConvertFrom-Json
进行转换,但我想知道您是否还需要它,因为您可以通过以下操作进行访问:
$name = $Request.Query.baz
my binding is same as yours. 我的约束力和你一样。 Hope it helps.
希望能帮助到你。
Let me know if you still need any help. 让我知道您是否仍然需要任何帮助。
Are you looking for something like this? 您是否正在寻找这样的东西?
using namespace System.Net
param($Request, $TriggerMetadata)
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $Request.RawBody | ConvertFrom-Json | ConvertTo-Json
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.