CSV is a wildly used and much faster data storage format that contain comma-separated values. It is normally used to store tabular data that can also be imported into a spreadsheet application. CSV format does not support complex data hierarchies. JSON is an easier to read and light-weight structured data file format. It is an alternative to XML file for storing and transferring data across platforms. If you want to transfer the tabular data or store the structured data into tabular form, it requires you to convert file formats into one another. In this article, I will show you how to convert CSV to JSON or JSON to CSV Programmatically in C#.
The following topics shall be covered in this blog post:
- JSON to CSV and CSV to JSON Conversion API and C# SDK
- How to Convert CSV to JSON in C# using REST API
- Convert Large JSON to CSV in C# using REST API
JSON to CSV and CSV to JSON Conversion API and C# SDK
For converting CSV file to JSON format and JSON to CSV file, I will be using the .NET SDK of GroupDocs.Conversion Cloud API. It is a feature-rich and high-performance Cloud SDK to convert back and forth between over 50 types of documents and images, including all Microsoft Office and OpenDocument file formats, PDF , HTML, CAD, raster images and many more. GroupDocs.Conversion Cloud API allows you to convert a wide list of supported source document formats into any other supported file format. It provides a flexible set of settings to customize the conversion process. Currently, it supports C#, Java, PHP, Ruby, Python and Node.js SDKs as its document conversion family members for the Cloud API.
You can install .Net SDK to your Visual Studio project using NuGet Package manager or by using the following command in the .Net CLI terminal:
dotnet add package GroupDocs.Conversion-Cloud --version 22.10.0
You also need to get your Client ID and Client Secret from the dashboard before you start following the steps and available code samples. Add your Client ID and Client Secret in the code as demonstrated below:
How to Convert CSV to JSON in C# using REST API
Now, convert CSV to JSON file by following the simple steps as mentioned below:
- Upload the input CSV file to the cloud
- Convert large CSV to JSON file in CSharp
- Download the converted file
Upload the File
Firstly, upload the CSV file to the cloud using the code example given below:
As a result, the uploaded CSV file will be available in the files section of your dashboard on the cloud.
Convert CSV to JSON Online using C#
The following steps allow you to convert JSON file to CSV file format programmatically in C# application.
- Firstly, create an instance of the ConvertApi
- Create convert settings instance using ConvertSettings
- Set input CSV file path
- Provide the output format as “json”
- Next, provide the output file path
- After that, create the ConvertDocumentRequest with ConvertSettings as an argument
- Finally, convert CSV to JSON by calling the convert_document() with ConvertDocumentRequest
The following code sample shows how to change CSV to JSON format in C# using REST API:
Finally, the above code sample will save the converted JSON file on the cloud.
Download the Converted File
The above code sample will save the converted CSV to JSON file on the cloud. You can download it using the following code sample:
Convert Large JSON to CSV in C# using REST API
The following steps allow converting the JSON file to CSV file in your C# application.
- First, create an instance of the ConvertApi
- Then, create convert settings instance using ConvertSettings
- Next, set input JSON file path
- Provide the output format as “csv”
- Next, provide the output file path
- Now, create the ConvertDocumentRequest with ConvertSettings as an argument
- Finally, convert JSON to CSV online by calling the convert_document() method with ConvertDocumentRequest
The following code sample shows how to convert JSON file to CSV document using C# REST API:
Finally, the above code sample will save the CSV file on the cloud.
Online JSON to CSV Converter Free
How to convert JSON to CSV online? Try online JSON to CSV converter for free to convert JSON to CSV online, which has been developed using the Groupdocs.Conversion Cloud APIs.
Online CSV to JSON Converter Free
How to convert CSV file to JSON online? Groupdocs.Conversion provides CSV to JSON converter online free to convert CSV to JSON array. It has been developed using the Groupdocs.Conversion Cloud APIs.
This brings us to the end of this blog post. In this article, you have learned:
- how to convert CSV to JSON programmatically;
- how to import JSON to CSV in C# programmatically;
Additionally, you can learn more about GroupDocs.Conversion conversion API using the documentation, or by examples available on GitHub. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser.
Finally, groupdocs.com is writing new interesting blog posts. So, please get in touch for regular updates.
Ask a question
You can ask your queries or questions, via our Free Support Forum
How do I convert CSV file to JSON in C#?
Please follow this link to learn the C# code snippet for how to create a JSON from CSV quickly.
How to convert nested JSON to CSV in C#?
Please follow this link to learn the C# code snippet to convert JSON to CSV file easily and quickly.
- Convert Word to PDF Programmatically in C#
- Convert PDF to Excel in Python using REST API
- How to Convert JPG to Word in Python
- How to Convert EXCEL to JSON and JSON to EXCEL in Python
- Convert CSV to JSON and JSON to CSV in Python
- Convert PowerPoint PPT/PPTX to JPG/JPEG Images in Python
- How to Extract Pages From Word Documents in Python