0

I'm using an Azure Logic App to get Blob contents from my storage account. The Blob-file is in .CSV format. I want to convert the CSV file into JSON.

I'm aware of the third party connectors like Plumsail documents, but they are paid. Is there a no-cost solution to this?

Any help would be greatly appreciated. Thanks!

2 Answers 2

5

You can split the content of the csv file using the split method, then store it in an array through traversal, and then append it into a Json string.

For example, the content of the csv file is

test1,test2,test3
testx,testy,testz

You need to split each line first, and then split each line with ,.

Note that \r\n is not easy to type in logic app, you can write it in Notepad first, and then paste it into ʻExpression`:

split(body('Get_blob_content_using_path'),'
')

enter image description here

You can refer to this post. Although it is very cumbersome, it still has reference significance.

=============update==================

The complete workflow is as follows:

enter image description here

enter image description here

enter image description here

Note:

In for each, you need to enable Concurrency Control and set its value to 1, otherwise it will execute in parallel and cause the append operation to be out of order.

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for you response @frank! What next after the For_each_2 step?
Sorry for the late reply, I have updated my answer, I hope it can be helpful to you.
0

You can create an Azure function using the PowerShell runtime and then use the PowerShell cmdlets ConvertFrom-CSV and ConvertTo-Json. The function can be called from the Logic App.

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."

$Output = $Request.Body | ConvertFrom-CSV | ConvertTo-Json

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
    StatusCode = [HttpStatusCode]::OK
    Body = $Output
})

https://learn.microsoft.com/en-us/azure/azure-functions/functions-versions?tabs=in-process%2Cv4&pivots=programming-language-powershell

https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-vs-code-powershell

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/convertto-json?view=powershell-7.2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.