逻辑应用程序 - 从 JSON 输出创建 CSV table

Logic App - Create CSV table from JSON output

我创建了一个 Runbook,它可以启动或关闭 VM,然后将结果输出到 JSON 输出中。我无法弄清楚如何获取该输出并在我的逻辑应用程序中的 'Create CSV Table' 中使用它。

输出(这正是它进入逻辑应用程序的方式):

[
    {
        'VM':  'MyVM2',
        'Success':  true,
        'PSComputerName':  'localhost',
        'PSShowComputerName':  true,
        'PSSourceJobInstanceId':  '286eeccb-c7f6-4afd-a734-7f4e837ffdac'
    },
    {
        'VM':  'MyVM1',
        'Success':  true,
        'PSComputerName':  'localhost',
        'PSShowComputerName':  true,
        'PSSourceJobInstanceId':  '286eeccb-c7f6-4afd-a734-7f4e837ffdac'
    }
]

我的逻辑应用流程:

但是当它运行时提示我以下错误,因为“创建 CSV Table”不喜欢输入:

我确定这只是某种格式需要更改,但我不确定如何更改。我是学习代码的新手,据我所知,输出是一个对象数组,但错误是要求一个数组。也许是某种限制?

我知道使用 Pars JSON,但是结果并不总是相同。有时我会在输出中有 2 个结果,或者有时我会有 20 个结果。因此,如果我在 Parse JSON 中仅定义 2 个结果的模式,它将忽略其余部分,因为它们未定义。

请按照以下步骤操作:

1) 首先你需要删除 "Compose" 动作

2) 在 "Create CSV Table" 操作中 从文本框传递 "Get Job output" 的内容 您传入的操作连接器 "Compose" Action

然后它的工作

问题:当您将 "Get Job output" 动作内容传递给 "Compose" 动作时,它会将内容数据类型数组转换为字符串。 "Create CSV Table" 仅数组数据类型内容

I'm aware of using Pars JSON, however the results will not always be the same. Sometimes I will have 2 results in the output, or sometimes I will have 20 results. Therefore if I define the schema in Parse JSON for only 2 results, it will omit the rest because they are not defined.

你也可以使用Pars JSON,如果每条记录的属性是固定的。请尝试使用以下架构。我在我这边测试它,它工作正常。

{
    "items": {
        "properties": {
            "PSComputerName": {
                "type": "string"
            },
            "PSShowComputerName": {
                "type": "boolean"
            },
            "PSSourceJobInstanceId": {
                "type": "string"
            },
            "Success": {
                "type": "boolean"
            },
            "VM": {
                "type": "string"
            }
        },
        "required": [
            "VM",
            "Success",
            "PSComputerName",
            "PSShowComputerName",
            "PSSourceJobInstanceId"
        ],
        "type": "object"
    },
    "type": "array"
}

对已经回答问题的人表示歉意,但在那段时间我能够创建一个 table 不同的方式,并且从那以后我的逻辑应用程序取得了很大的进步。

Create_CSV_table": {
            "inputs": {
                "format": "CSV",
                "from": "@json(outputs('Compose'))"
            },

...因此输出如下:

我希望您的回答对浏览此页面的任何人(或以后我自己)有所帮助。