Skip to content

Instantly share code, notes, and snippets.

@groupdocs-cloud-gists
Last active March 10, 2024 04:44
Show Gist options
  • Save groupdocs-cloud-gists/1b2fe21c7a309544342ca298986d658a to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/1b2fe21c7a309544342ca298986d658a to your computer and use it in GitHub Desktop.
Transform JSON to CSV
Develop JSON to CSV converter with C# .NET
// More examples over https://github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-dotnet
// Obtain your API credentials
string clientId = "4bdefca3-f08c-4088-9ca0-55c38f4b7f22";
string clientSecret1 = "a43c8b4365246a062688a259abe5b469";
// Create an instance of the Configuration class and initialize it with the Client ID & Client Secret.
var configurations = new GroupDocs.Conversion.Cloud.Sdk.Client.Configuration(clientId, clientSecret1);
// Define ApiBaseUrl to set the base url
configuration.ApiBaseUrl = "https://api.groupdocs.cloud";
// Initialize an instance of the ConvertApi class with the object of the Configuration class.
var apiInstance = new GroupDocs.Conversion.Cloud.Sdk.Api.ConvertApi(configurations);
// load the input JSON from local drive
using (var stream = System.IO.File.OpenRead("input.json"))
{
// create an instnace of FileApi
var fileUpload = new FileApi(configurations);
// upload the input JSON file to cloud storage with provided name
fileUpload.UploadFile(new UploadFileRequest("input.json", stream));
// create ConvertSettings object where we define the input JSON and name for resultant CSV
var settings = new ConvertSettings
{
StorageName = "internal",
FilePath = "input.json",
Format = "csv",
OutputPath = "resultant.csv"
};
// Invoke the ConvertDocument method to transform JSON to CSV programmatically.
var response = apiInstance.ConvertDocument(new GroupDocs.Conversion.Cloud.Sdk.Model.Requests.ConvertDocumentRequest(settings));
if (response != null && response.Equals("OK"))
{
// print succeess message
Console.WriteLine("The JSON to CSV conversion completed successfully !");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment