How to convert CSV to JSON in C# .NET Framework

Today’s topic is very straightforward: we are laying out how to convert between CSV and JSON formats. And we will be getting this done in a super simple manner, taking up just a few minutes of your valuable time.

Let’s blast things off with our API client installation! Piece of cake, just run this command in Package Manager and NuGet will do the rest.

Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 2.2.0

Now we can run the ConvertDataCsvToJson function on our CSV file, as you can see demonstrated right here:

using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;namespace Example{public class ConvertDataCsvToJsonExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new ConvertDataApi();var inputFile = new System.IO.Stream(); // System.IO.Stream | Input file to perform the operation on.try{// Convert CSV to JSON conversionObject result = apiInstance.ConvertDataCsvToJson(inputFile);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling ConvertDataApi.ConvertDataCsvToJson: " + e.Message );}}}}

Not much else needs to be said, you’re done. The CSV is now a JSON and ready to be used however you like. If you would like to check out more useful functions like this with equally simple implementation, take a look at the other articles in this sequence. They cover everything from format conversion to document creation and editing. Just think of the time you’ll be saving.

Image for post
Image for post

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store