Posts

Showing posts from October, 2022

How to Validate JSON in C# Effortlessly using JSON Schema file?

Image
  There are situations where we may need to validate JSON data which we are receiving from external sources. This is done to ensure data integrity. This can be done easily with the help of a JSON Schema file which lists down the constraints and the template of JSON data. Validating JSON using JSON Schema in C# In this post we are going to see with an example, How we can validate the JSON data against the JSON Schema we are using. For this I have created a JSON Schema which lays down the template for the JSON data along with the constraints for the properties of JSON data. Next is to create the JSON data, for this demo, I have hardcoded the JSON data as a string. Below code demonstrates these in action: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 using Newtonsoft.Json.Linq ; using Newtonsoft.Json.Schema ; using Syst...

How to Generate JSON from JSON Schema File in .Net C#?

Image
  Many a times we may have the JSON Schema file describing the JSON content type and its format. Our requirement may be to generate a JSON file from the Schema with the default values for the properties populated from the Schema file. Here we are going to see how this can be done using a simple static utility class in .Net. Generating Default JSON from JSON Schema file For this example I have created a Console Application in C# .Net Framework, and in the Program.cs file I have hardcoded the JSON Schema which acts as our input to generate the JSON. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 ...

How to Check Memory Leaks From Running the Application using UMDH?

While running some applications we might have noticed the memory resource consumption going high, This is all fine if the memory gets released when the application is stopped or killed. But what if the memory consumption does not come down even after the application is killed or stopped? This is when we say that Memory Leaks are present in the application. Tricky part is how can we identify them? For a simple application finding the root cause can be tricky no need to mention how challenging it would be to find the root cause in the case of large commercial application which is composed of several modules. In these situations UMDH can come to the rescue by pointing out the memory allocation and deallocation by each modules present in the process and giving hints where it might be going wrong. UMDH is typically used in situations where we have to find memory leak in the execution path of some action being performed. Following are the steps that needs to be done for narrowing down to...

How to Auto Generate CMakeList file and Build C++ project in VS Code?

Image
Introduction   VS Code is a lightweight fast and easy to use editor for developing software in any language. Traditionally most of us use Visual Studio for our development purposes especially if we are developing in C++. One of the Key advantage while using VS Code to develop applications in C++ is that developer can solely focus on creating source file and these can be bundled in a project or solution file using CMake with any compiler and build configuration. Here we are going to see step by step how to Auto generate CMakelist file in VS Code which specifies the source files that needs to be bundled together and the build configuration etc. Installing CMake Tool Extension Before we get started we need to install extension for CMake Tools in VS Code. I Have installed extension from Microsoft for this purpose as shown in the figure below:   Create a sample C++ file with some code as shown in the figure below in the folder which is loaded in VS Code Next step is to use Com...