A JSON serializer/deserializer library written in pure C#.
VJson
is a JSON serializer/deserializer (with JsonSchema support) library written in pure C#. Supported versions are .NET Framework 3.5
and .NET Standard 1.6
or higher.
This library is developed as a purely C# project, however it also supports that be build with Unity 2018.3.12f1
or higher.
You can use Nuget/VJson.
dotnet add package VJson
(TODO: Provide unity packages)
//
// For serialization
//
var serializer = new VJson.JsonSerializer(typeof(int));
// You can get JSON strings,
var json = serializer.Serialize(42);
// OR write json data(UTF-8) to streams directly.
using (var s = new MemoryStream())
{
serializer.Serialize(s, 42);
}
//
// For deserialization
//
var serializer = new VJson.JsonSerializer(typeof(int));
// You can get Object from strings,
var value = serializer.Deserialize(json);
// OR read json data(UTF-8) from streams directly.
using (var s = new MemoryStream(Encoding.UTF8.GetBytes(json)))
{
var value = serializer.Deserialize(s);
}
VJson
supports serializing/deserializing of some System.Collections(.Generics)
classes listed below,
- List
- Dictionary<string, T>
- Array
and user defined classes. For user defined classes, converting only all public fields are supported.
e.g.
class SomeObject
{
private float _p = 3.14f; // A private field will not be exported.
public int X;
public string Y;
}
var obj = new SomeObject {
X = 10,
Y = "abab",
},
var serializer = new VJson.JsonSerializer(typeof(SomeObject));
var json = serializer.Serialize(obj);
// > {"X":10,"Y":"abab"}
var v = serializer.Deserialize("{\"X\":10,\"Y\":\"abab\"}");
// > v becomes same as obj.
VJson
supports JSON Schema draft7.
(TODO: Write examples)
(TODO: Write examples)
Other use cases are available at here.
- Performance tuning