Skip to content
This repository has been archived by the owner on Mar 19, 2019. It is now read-only.
/ UniJSON Public archive

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

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta
Notifications You must be signed in to change notification settings

ousttrue/UniJSON

Repository files navigation

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

About

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

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •