AnythingToJson 0.0.17
dotnet add package AnythingToJson --version 0.0.17
NuGet\Install-Package AnythingToJson -Version 0.0.17
<PackageReference Include="AnythingToJson" Version="0.0.17" />
paket add AnythingToJson --version 0.0.17
#r "nuget: AnythingToJson, 0.0.17"
// Install AnythingToJson as a Cake Addin #addin nuget:?package=AnythingToJson&version=0.0.17 // Install AnythingToJson as a Cake Tool #tool nuget:?package=AnythingToJson&version=0.0.17
AnythingToJSON
AnythingToJSON is a lightweight C# library useful for converting symbol delimited data to JSON. Using just a memory stream or a provided file path, AnythingToJSON supports converting the following:
- Excel Files (.xlsx, .xlsm)
- CSVs (of any variety)
- C# DataTables
How to Use
Install via NuGet:
$ dotnet add package AnythingToJson
To use, simply create a new instance and pick the applicable method. When no delimiter is provided for CSV conversions, code will attempt to heuristically determine what delimiter is.
Available methods and constructors are:
AnythingToJsonConverter() <--- default constructor
AnythingToJsonConverter(ignore errors) <--- bool flag to return empty JSON object "{}" if an error occurs
ConvertCsvFromFilePath(path, delimiter, has header line)
ConvertCsvFromMemoryStream(memory stream, delimiter, has header line)
ConvertExcelFromPath(path)
ConvertExcelFromMemoryStream(memory stream)
ConvertFromMemoryStream(memory stream, delimiter, has header line)
ConvertDataTable(datatable)
ConvertThis(object)
Code Samples
Below are a few examples of how to use the library.
Use the File methods when converting a file locally.
Use the Memory Stream methods if you want to convert multipart/form-data
within an endpoint or the like.
Use the DataTable method if you want to convert a DataTable object to JSON.
From file:
CSV:
var converter = new AnythingToJsonConverter();
var csvFromPath = converter.ConvertCsvFromFilePath(@"CSV/semi-colon-example.csv");
Excel:
var converter = new AnythingToJsonConverter();
var excelFromPath = converter.ConvertExcelFromFilePath(@"Excel/excel-example.xlsx");
Memory Stream:
CSV:
byte[] data = File.ReadAllBytes(@"CSV/semi-colon-example.csv");
using var memoryStream = new MemoryStream(data);
var csvFromMemoryStream = converter.ConvertCsvFromMemoryStream(memoryStream);
Excel:
byte[] data = File.ReadAllBytes(@"Excel/excel-example.xlsx");
using var memoryStream = new MemoryStream(data);
var excelFromMemoryStream = converter.ConvertExcelFromMemoryStream(memoryStream);
DataTable:
AnythingToJsonConverter converter = new AnythingToJsonConverter();
DataTable table = new DataTable("Table Example");
table.Columns.Add("ID", typeof(int));
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Age", typeof(int));
table.Rows.Add(1, "John Doe", 30);
table.Rows.Add(2, "Jane Smith", 25);
table.Rows.Add(3, "Timothy James", 40);
var dataTableJson = converter.ConvertDataTable(table);
Example response from library:
[
{
"ID": 1,
"Name": "John Doe",
"Age": 30
},
{
"ID": 2,
"Name": "Jane Smith",
"Age": 25
},
{
"ID": 3,
"Name": "Timothy James",
"Age": 40
}
]
If you encounter any issues or have suggestions, please feel free to post them at the AnythingToJSON's GitHub
Happy coding and thank you for using this library!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- ClosedXML (>= 0.102.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.