A lightweight, high-performance JSON array encoder/decoder library for .NET. Provides simple, fast JSON array encoding and decoding without complex object mapping.
- ๐ Fast & Lightweight - Zero runtime dependencies, optimized for performance
- ๐ฆ Multi-Platform Support - Targets .NET Framework 4.5, .NET Standard 2.0, .NET 6.0, .NET 8.0, and .NET 9.0
- ๐ฏ Simple API - Easy-to-use static methods for encoding and decoding
- ๐ง Array-Focused - Specialized for JSON array operations
- โ Well-Tested - 98.31% code coverage with comprehensive unit tests using MSTest
- ๐ Pretty Printing - Built-in JSON formatting with proper indentation
- ๐ No External Dependencies - Pure .NET implementation with no third-party packages
- ๐ Tiny Package - Only 37KB package size
Install via NuGet Package Manager:
dotnet add package Echovoice.JSONOr via Package Manager Console:
Install-Package Echovoice.JSONusing Echovoice.JSON;
string input = "[\"philcollins\",\"Ih8PeterG\"]";
string[] result = JSONDecoders.DecodeJsStringArray(input);
// result[0]: "philcollins"
// result[1]: "Ih8PeterG"string input = "[14,4,[14,\"data\"],[[5,\"10.186.122.15\"],[6,\"10.186.122.16\"]]]";
string[] result = JSONDecoders.DecodeJSONArray(input);
// result[0]: "14"
// result[1]: "4"
// result[2]: "[14,\"data\"]"
// result[3]: "[[5,\"10.186.122.15\"],[6,\"10.186.122.16\"]]"
// Decode nested arrays
string[] nested = JSONDecoders.DecodeJSONArray(result[3]);
// nested[0]: "[5,\"10.186.122.15\"]"
// nested[1]: "[6,\"10.186.122.16\"]"string[] items = new[] { "hello", "world", "test" };
string result = JSONEncoders.EncodeJsStringArray(items);
// Result: ["hello","world","test"]public class Person
{
public string Name { get; set; }
public int Age { get; set; }
public override string ToString()
{
return $"[{Age},{JSONEncoders.EncodeJsString(Name)}]";
}
}
var people = new[]
{
new Person { Name = "Alice", Age = 30 },
new Person { Name = "Bob", Age = 25 }
};
string result = JSONEncoders.EncodeJsObjectArray(people);
// Result: [[30,"Alice"],[25,"Bob"]]using Echovoice.JSON.Pretty;
string input = "[14,4,[14,\"data\"],[[5,\"10.186.122.15\"],[6,\"10.186.122.16\"]]]";
string pretty = input.PrettyPrintJson();Output:
[
14,
4,
[
14,
"data"
],
[
[
5,
"10.186.122.15"
],
[
6,
"10.186.122.16"
]
]
]| Method | Description |
|---|---|
DecodeJSONArray(string s) |
Decodes a complex JSON array with nested structures |
DecodeJsStringArray(string s) |
Decodes a simple JSON string array |
DecodeJsString(string s) |
Decodes a JSON-encoded string with escape sequences |
| Method | Description |
|---|---|
EncodeJsStringArray(string[] s) |
Encodes a string array with proper escaping |
EncodeJsObjectArray(object[] s) |
Encodes an object array (uses ToString()) |
EncodeJsObjectList<T>(List<T> s) |
Encodes a generic list (uses ToString()) |
EncodeJsString(string s) |
Encodes a single string with JSON escaping |
| Method | Description |
|---|---|
string.PrettyPrintJson() |
Formats JSON with proper indentation |
string.Slice(int start, int end) |
Python-like string slicing (supports negative indices) |
| Feature | Echovoice.JSON | Json.NET | System.Text.Json |
|---|---|---|---|
| Runtime Dependencies | Zero | Multiple | None (built-in) |
| Package Size | Minimal (~35KB) | Large (~700KB) | Built-in |
| Array Focus | โ | โ | โ |
| Simple API | โ | โ | |
| .NET Framework 4.5 | โ | โ | โ |
| Performance | Fast | Medium | Fast |
| Memory Footprint | Minimal | Large | Medium |
When to use Echovoice.JSON:
- You need simple JSON array encoding/decoding
- You want zero runtime dependencies
- You're working with legacy .NET Framework projects
- You need a tiny package size
- You don't need complex object serialization
- You want minimal memory overhead
When to use alternatives:
- You need full JSON object serialization
- You need LINQ-to-JSON capabilities
- You need streaming JSON parsing
git clone https://github.com/echovoice/Echovoice.JSON.git
cd Echovoice.JSON
dotnet builddotnet testdotnet test --collect:"XPlat Code Coverage"Current code coverage: 98.31%
- Line coverage: 98.31% (175/178)
- Branch coverage: 97.71% (169/173)
- Method coverage: 100% (12/12)
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
- String slicing extension credit: DotNetPerls
- Original encode inspiration: Rick Strahl's Blog
- ๐ง Issues: GitHub Issues
- ๐ฆ NuGet: Echovoice.JSON
Made with โค๏ธ by Echovoice