簡體   English   中英

使用帶有PowerShell和HTTP觸發器的Azure函數的JSON Prettifier

[英]JSON Prettifier Using Azure Function w/ PowerShell and HTTP Trigger

以為這很簡單,但是a,我無法弄清楚。 看來PowerShell將使用單個cmdlet來美化JSON

目標 :使用PowerShell Azure Function應用美化JSON

  • 使用Microsoft Flow,將HTTP請求(POST)發送到帶有“ ugly”的Azure函數,該消息在正文中已序列化
  • Azure Function讀入文件(然后使用ConvertToJson cmdlet進行美化?)並將文件輸出回Flow

問題

  1. 我要在Azure函數的run.ps1區域中放置什么來實現此目的? 在此處輸入圖片說明
  2. 我要在Azure函數的functions.json區域中放置什么以實現此目的? 在此處輸入圖片說明

我在下面采取了序列化字符串

'{ "baz": "quuz", "cow": [ "moo", "cud" ], "foo": "bar" }'

在Powershell 3的Prettify json中提到過

這是我與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
})

在下面,您可以看到,我可以從我發布的字符串中讀取它。

在此處輸入圖片說明

您可以使用ConvertFrom-Json進行轉換,但我想知道您是否還需要它,因為您可以通過以下操作進行訪問:

$name = $Request.Query.baz

我的約束力和你一樣。 希望能幫助到你。

讓我知道您是否仍然需要任何幫助。

您是否正在尋找這樣的東西?

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM