简体   繁体   English

使用带有PowerShell和HTTP触发器的Azure函数的JSON Prettifier

[英]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

  • Using Microsoft Flow, send an HTTP request (POST) to an Azure Function w/ "ugly", serialized JSON file in body 使用Microsoft Flow,将HTTP请求(POST)发送到带有“ ugly”的Azure函数,该消息在正文中已序列化
  • Azure Function reads file in (then uses ConvertToJson cmdlet to prettify?) and outputs the file back to Flow Azure Function读入文件(然后使用ConvertToJson cmdlet进行美化?)并将文件输出回Flow

Questions : 问题

  1. What do I put in the run.ps1 area of the Azure Function to make this happen? 我要在Azure函数的run.ps1区域中放置什么来实现此目的? 在此处输入图片说明
  2. What do I put in the functions.json area of the Azure Function to make this happen? 我要在Azure函数的functions.json区域中放置什么以实现此目的? 在此处输入图片说明

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.

相关问题 JSON 作为 Javascript object 在 Azure http 触发器 function - JSON as Javascript object in Azure http trigger function Azure Function HTTP 触发器接收嵌套的 Z0ECD11C1D7A287401D148A23BBD7 - Azure Function HTTP trigger to receive nested JSON and store in Cosmos DB 带有 HTTP 触发器的 Azure 函数无法从 JSON 负载绑定模型(.NET 5 out-of-proc) - Azure Function with HTTP trigger fails to bind model from JSON payload (.NET 5 out-of-proc ) 使用 Powershell 对 http 请求进行 JSON 对象格式化 - JSON Object Formatting using Powershell for http request Azure Logic App HTTP请求触发器中的JSON有效负载格式 - Format of JSON payload in Azure Logic App HTTP Request trigger 具有 HTTP 触发器和 Blob 输入绑定的 Azure 函数 - 无法读取文件夹中的 JSON 文件。 可能的 blob 文件路径错误? - Azure Function with HTTP Trigger and Blob Input Binding - can't read JSON files that are in a folder. Possible blob file path error? Azure Function App Push-OutputBinding Adding Subscription Information to JSON Output using Powershell - Azure Function App Push-OutputBinding Adding Subscription Information to JSON Output using Powershell 在 powershell azure ZC1C425268E687A94D1AB5074C 的请求正文中访问 json 值的困难 - Difficulties accessing json values in request body of powershell azure function 使用 powershell 部署 Azure Json 策略时出错 - Error while deploying Azure Json policy using powershell json webservice 输出到带有凭据的 azure sql - json webservice output to azure sql w/ credentials
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM