Skip to content

Fast flexible json serialiser & deserialiser with support for contract-based workflows

License

Notifications You must be signed in to change notification settings

i-e-b/SkinnyJson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SkinnyJson

SkinnyJson has a simple interface, and handles interface based serialisation better than most other .Net json libraries. SkinnyJson was designed to handle Event Store messages, and is tuned to deal with situations where a common interface declaration is available, but the original serialised objects/types are not available.

Things SkinnyJson can do that most .Net serialisers don't

  • Decode directly to an interface: IThing x = Json.Defrost<IThing>(...). You don't need to create a concrete container.
  • Serialise to and from static classes: var jsonStr = Json.Freeze(typeof(MyStatic)); Json.DefrostTo(typeof(MyStatic), jsonStr);
  • Reformat huge documents: Json.BeautifyStream(fileStreamIn, Encoding.ASCII, fileStrealOutput, Encoding.UTF8);

Common use cases:

Deserialise a known type:

IMyInterface values = Json.Defrost<IMyInterface>(jsonString);

Serialise any object to JSON:

string jsonString = Json.Freeze(myObject);

Pretty print a JSON string: (there is also a streaming version for very large files)

var newString = Json.Beautify(oldString);

Create a deep copy of an object:

var newObject = Json.Clone(oldObject);

Deserialise to a dynamic type for unknown schemas:

dynamic obj = Json.DefrostDynamic(jsonString);
Console.WriteLine(obj.MyProperty.MyArray[4].Prop2()); // use `()` to read a value.
var missing = obj.NotHere.child.grandchild(); // results in null. Dynamic does null propagation.

obj.MyProperty.other = "hello"; // can update properties
var updatedJson = Json.Freeze(obj); // and serialise the result

Inline editing:

string newJson = Json.Edit(oldJson, d => {
    d.myProperty.updated = true;
    d.info.updates[0].dateTime = DateTime.Now.ToString();
});

See the test cases for deeper examples

Based on FastJson: https://github.com/mgholam/fastJSON

Releases

No releases published

Packages

No packages published

Languages