https://github.com/joshua-light/pocket.json
Simple JSON serialization/deserialization library.
https://github.com/joshua-light/pocket.json
csharp json serialization
Last synced: about 2 months ago
JSON representation
Simple JSON serialization/deserialization library.
- Host: GitHub
- URL: https://github.com/joshua-light/pocket.json
- Owner: joshua-light
- License: mit
- Created: 2018-01-21T18:25:49.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-07-07T17:42:58.000Z (almost 4 years ago)
- Last Synced: 2025-09-12T16:52:09.882Z (10 months ago)
- Topics: csharp, json, serialization
- Language: C#
- Homepage:
- Size: 220 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pocket.Json

[](https://www.nuget.org/packages/Pocket.Json)
_A simple JSON serialization/deserialization library that is pretty fast._
_(It doesn't match 100% of JSON spec, and was made just for learning purposes.)_
## Usage
### Data Format
```c#
// Class should be `public`.
public class Point
{
// Fields should be just `public`.
[Json] public int X;
[Json] public int Y;
// A public parameterless constructor should be defined (either implicitly or explicitly).
public Point() { }
}
```
### Serialize
```c#
var json = new Point { X = 1, Y = 2 }.ToJson();
```
### Deserialize
```c#
var point = json.FromJson();
```
## Benchmarks
Code for benchmarks can be found [here](https://github.com/JoshuaLight/Pocket.Json/blob/master/src/Benchmarks/Program.cs).
```
BenchmarkDotNet=v0.12.1, OS=elementary 5.1.5
Intel Core i9-9900KF CPU 3.60GHz (Coffee Lake), 1 CPU, 16 logical and 8 physical cores
.NET Core SDK=3.1.301
[Host] : .NET Core 3.1.5 (CoreCLR 4.700.20.26901, CoreFX 4.700.20.27001), X64 RyuJIT
DefaultJob : .NET Core 3.1.5 (CoreCLR 4.700.20.26901, CoreFX 4.700.20.27001), X64 RyuJIT
```
### Serialization
| Method | Mean | Error | StdDev |
|--------------- |----------:|---------:|---------:|
| NewtonsoftJson | 274.29 μs | 1.478 μs | 1.310 μs |
| Utf8Json | 99.78 μs | 0.537 μs | 0.476 μs |
| PocketJson | 108.07 μs | 0.434 μs | 0.362 μs |
### Deserialization
| Method | Mean | Error | StdDev |
|--------------- |----------:|---------:|---------:|
| NewtonsoftJson | 401.33 μs | 3.472 μs | 3.077 μs |
| Utf8Json | 130.03 μs | 1.492 μs | 1.395 μs |
| PocketJson | 79.60 μs | 0.286 μs | 0.267 μs |