1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

つづくAdvent Calendar 2023

Day 7

Logic Apps で CSV 2 JSON する

Posted at

CSV 2 JSON、略して C2J かどうかは知らないが、

これを
image.png

こうします、という小話。
image.png

ARM
{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "BLOB_コンテンツを取得する_(V2)": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['azureblob_1']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('https://noystorageaccount.blob.core.windows.net/'))}/files/@{encodeURIComponent(encodeURIComponent('JTJmZm9sZGVyJTJmdW1pbm9jb21wYW55LmNzdg=='))}/content",
                    "queries": {
                        "inferContentType": true
                    }
                },
                "metadata": {
                    "JTJmZm9sZGVyJTJmdW1pbm9jb21wYW55LmNzdg==": "/folder/uminocompany.csv"
                },
                "runAfter": {},
                "type": "ApiConnection"
            },
            "For_each": {
                "actions": {
                    "SplitByComma": {
                        "inputs": "@split(item(), ',')",
                        "runAfter": {},
                        "type": "Compose"
                    },
                    "作成": {
                        "inputs": {
                            "メールアドレス": "@{outputs('SplitByComma')?[3]}",
                            "社員名称": "@{outputs('SplitByComma')?[1]}",
                            "社員番号": "@{outputs('SplitByComma')?[0]}",
                            "電話番号": "@{outputs('SplitByComma')?[2]}"
                        },
                        "runAfter": {
                            "SplitByComma": [
                                "Succeeded"
                            ]
                        },
                        "type": "Compose"
                    }
                },
                "foreach": "@skip(outputs('SplitbyLine'),1)",
                "runAfter": {
                    "SplitbyLine": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "SplitbyLine": {
                "inputs": "@split(body('BLOB_コンテンツを取得する_(V2)'), decodeUriComponent('%0D%0A'))",
                "runAfter": {
                    "BLOB_コンテンツを取得する_(V2)": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            },
            "json": {
                "inputs": "@outputs('作成')",
                "runAfter": {
                    "For_each": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {
        "$connections": {
            "value": {
                "azureblob_1": {
                    "connectionId": "/subscriptions/<SubscriptionID>/resourceGroups/<ResourceGroup>/providers/Microsoft.Web/connections/azureblob",
                    "connectionName": "azureblob",
                    "connectionProperties": {
                        "authentication": {
                            "type": "ManagedServiceIdentity"
                        }
                    },
                    "id": "/subscriptions/<SubscriptionID>/providers/Microsoft.Web/locations/japaneast/managedApis/azureblob"
                }
            }
        }
    }
}

マネージド ID が使えるところが便利です。
image.png

つづく

前職では外部連携と言えば CSV 出力、CSV 取込 ばかりだったのですが、JSON 楽しいですね。

こんな記事もあります。つづく。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?