Paste JSON/XML as classes in Visual Studio – Quick Tip

Hi Folks,

With this post I will show you how you can quickly add classes for your JSON and XML in Power Platform using Visual Studio.

Sometimes, there will be requirements where you need to convert and replace your Power Automate Flows with custom code either using Plugins or Actions. In this case, you may definitely need to parse the response returned by REST API calls and you might need to create relevant classes to hold the parameters and attributes, creating these manually would be cumbersome and takes few minutes of time even for a good developer.

Here I am taking the example using JSON.

So, without further due, let’s see in this in action.

Step 1: So, just copy using Cntrl + C shortcut, this is mandatory, else you will not able to see the Paste JSON as Classes and Paste XML as classes under edit..

{
"orderId": "ORD123456",
"customerName": "John Doe",
"orderDate": "2024-04-27T08:30:00Z",
"items": [
{
"itemId": "ITEM001",
"itemName": "Product A",
"quantity": 2,
"unitPrice": 25.99
},
{
"itemId": "ITEM002",
"itemName": "Product B",
"quantity": 1,
"unitPrice": 35.50
}
],
"totalAmount": 87.48,
"shippingAddress": {
"street": "456 Elm St",
"city": "Metropolis",
"zipcode": "54321",
"country": "USA"
},
"status": "Shipped"
}

Step 2: Then open Visual Studio –> Edit –> Paste Special

Step 3: Click on Paste JSON As Classes and soon you should be able to see something as below.

That’s it, your classes are now generated from the copied JSON File, you can do pretty much the similar thing with XML.

Hope this helps someone trying to achieve a similar goal…

Cheers,
PMDY

Calling Command Line Commands from C# – Quick Tip

Hi Folks,

In today’s no code world and AI, while most of the Apps are developed using low code approach, sometimes we have to go with the traditional way of development to handle any integrations with other systems.

When we give anyone Command Line script and ask them to execute, the other person would immediately open Search bar at the bottom available in Windows and start entering cmd. Immediately command prompt window appears and will be able to execute the same command.

But what if we ask to execute command line Commands from C# code…? So, in this blog post, I will show you how easily you can call command line commands with a simple example. Let’s get started…

Here in order to showcase, I will just use a basic command line command and run it from C#.

Everyone knows how to find the ipconfig command right, which just shows the internet protocol configuration when entered in command line like below.

In order to execute it from Console Application using C#, we would need to utilize the System. Diagnostics. You can utilize the below C# code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace BatchTest
{
class Program
{
static void Main(string[] args)
{
Process pro = new Process();
pro.StartInfo.FileName = "cmd.exe";
pro.StartInfo.CreateNoWindow = true;
pro.StartInfo.RedirectStandardInput = true;
pro.StartInfo.RedirectStandardOutput = true;
pro.StartInfo.RedirectStandardError = true;
pro.StartInfo.UseShellExecute = false;
pro.Start();
pro.StandardInput.WriteLine("ipconfig");
pro.StandardInput.Flush();
pro.StandardInput.Close();
pro.WaitForExit();
Console.WriteLine(pro.StandardOutput.ReadToEnd());
Console.ReadKey();
}
}
}

When we execute this command, it shows exactly same as what we saw above with Command Line.

In the same way we can call any Command Line Commands from C#. I have to use this approach for my Power Platform Implementation integration to decrypt encrypted messages using PGP and I found it to be very helpful and thought of sharing with all of you. If you were looking for a program to decrypt, you can check out for previous blog post here.

Cheers,

PMDY