Skip to content

saturday06/VJson

 
 

Repository files navigation

VJson 🍣

A JSON serializer/deserializer library written in pure C#.

CircleCI NuGet Badge codecov license

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.

Installation

For standard C# projects

You can use Nuget/VJson.

dotnet add package VJson

For Unity projects

(TODO: Provide unity packages)

Usage example

Serialize/Deserialize

//
// 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.

Attributes

JSON Schema and validation

VJson supports JSON Schema draft7.

(TODO: Write examples)

Attributes

(TODO: Write examples)

Other use cases are available at here.

Tasks

  • Performance tuning

License

Boost Software License - Version 1.0

References

Author

About

A JSON serializer/deserializer library written in pure C#

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 97.4%
  • Python 1.4%
  • Makefile 1.2%