Convert CSV to JSON using Standard Logic Apps

78 Views Asked by At

I am new to LogicApps. I have below scenario to implement.

I have a scenario where I have to convert CSV data to JSON using standard LogicApps. I have to pick the CSV file from Azure File share and convert it to JSON, and store the JSON file to Azure Fileshare. Can someone help me with the steps to achieve this?

Below is Input CSV and Expected Output

Input CSV Data

CustomerName,OrderID,Orderdate,ItemNumer,ItemPrice
Rahul,ORD123,18-01-2024,ITM001,150.00
Rahul,ORD133,18-01-2024,ITM002,200.00
Rajib,ORD234,18-01-2024,ITM123,100.00
Rahul,ORD123,18-01-2024,ITM003,250.00
Rajib,ORD234,18-01-2024,ITM125,500.00
Rahul,ORD133,18-01-2024,ITM004,300.00

Expected JSON Output Data:

{
  "orderdetails": [
    {
      "customername": "Rahul",
      "orders": [
        {
          "OrderID": "ORD123",
          "Orderdate": "18-01-2024",
          "Itemdetails": [
            {
              "itemnumber": "ITM001",
              "itemprice": "150.00"
            },
            {
              "itemnumber": "ITM003",
              "itemprice": "250.00"
            }
          ]
        },
        {
          "OrderID": "ORD133",
          "Orderdate": "18-01-2024",
          "Itemdetails": [
            {
              "itemnumber": "ITM002",
              "itemprice": "200.00"
            },
            {
              "itemnumber": "ITM004",
              "itemprice": "300.00"
            }
          ]
        }
      ]
    },
    {
      "customername": "Rajib",
      "orders": [
        {
          "OrderID": "ORD234",
          "Orderdate": "18-01-2024",
          "Itemdetails": [
            {
              "itemnumber": "ITM123",
              "itemprice": "100.00"
            },
            {
              "itemnumber": "ITM125",
              "itemprice": "500.00"
            }
          ]
        }
      ]
    }
  ]
}

Any help with the steps is appreciated.

1

There are 1 best solutions below

0
RithwikBojja On

Below is then design which will work in Consumption and Standard Logic apps too and provided expected results:

enter image description here

Compose : -split(body('Get_file_content'),decodeUriComponent('%0D%0A'))

enter image description here

Compose 2:

split(first(outputs('Compose')), ',')

Select action:

{
  "orderdetails": [
    {
  "@{outputs('Compose_2')[0]}": @{split(item(), ',')?[0]},
  "orders": [
    {
      "@{outputs('Compose_2')[1]}": @{split(item(), ',')?[1]},
      "@{outputs('Compose_2')[2]}": @{split(item(), ',')?[2]},
      "Itemdetails": [
        {
          "@{outputs('Compose_2')[3]}": @{split(item(), ',')?[3]},
          "@{outputs('Compose_2')[4]}": @{split(item(), ',')?[4]}
        }
      ]
    }
  ]
}
]
}

(@ has come while copying it)

enter image description here

Output:

enter image description here