Uni JSON by ousttrue - 5

Tools

JSON serializer and deserializer and schema utilities for Unity(.Net3.5)

Unknown VersionOtherUpdated 1 year agoCreated on May 11th, 2018
Go to source

I decided to integrate this library with UniVRM for maintenance reason (submodule burdensome). Continue updating within UniVRM

UniJSON

JSON serializer and deserializer and schema utilities for Unity(.Net3.5)

Usage

JSON Create

var f = new JsonFormatter();
f.BeginMap();
f.Key("X"); f.Value(1);
f.Key("Y"); f.Value(1);
f.Key("Z"); f.Value(1);
f.EndMap();
var json = f.ToString();
// {"X":1,"Y":2,"Z":3}

JSON Serialize

Serialize public fields automatically.

var f = new JsonFormatter();
f.Serialize(new Vector3(1, 2, 3));
var json = f.ToString();
// {"X":1,"Y":2,"Z":3}

JSON Parse

var json = "{\"X\":1,\"Y\":2,\"Z\":3}";
var parsed = json.ParseAsJson();
var x = parsed["X"].GetInt32();

JSON Deserialize

var v = default(Vector3);
json.Deserialize(ref v);

JSON Schema

[Serializable]
public class glTFSparseIndices
{
    [JsonSchema(Minimum = 0)]
    public int bufferView;

    [JsonSchema(Minimum = 0)]
    public int byteOffset;

    [JsonSchema(EnumSerializationType = EnumSerializationType.AsInt)]
    public glComponentType componentType;

    // empty schemas
    public object extensions;
    public object extras;
}


[Test]
public void AccessorSparseIndices()
{
    // from JSON schema
    var path = Path.GetFullPath(Application.dataPath + "/../glTF/specification/2.0/schema");
    var SchemaDir = new FileSystemAccessor(path);
    var fromSchema = JsonSchema.ParseFromPath(SchemaDir.Get("accessor.sparse.indices.schema.json"));

    // from C# type definition
    var fromClass = JsonSchema.FromType<glTFSparseIndices>();

    Assert.AreEqual(fromSchema, fromClass);
}

MsgPack

Same as json interface

var f = new MsgPackFormatter();
f.Serialize(new Vector3(1, 2, 3));
ArraySegment<byte> msgpack = f.GetStoreBytes();

var parsed = msgpack.ParseAsMsgPack();
var x = parsed["X"].GetInt32();

TOML

WIP

var toml =@"
X = 1
Y = 2
Z = 3
";
var parsed = toml.ParseAsToml();
var x = parsed["X"].GetInt32();

Reference

JSON

JSON Schema

JSON Patch

JSON RPC

MsgPack

MsgPack-RPC

TOML

Show all projects by ousttrue