Coder Social home page Coder Social logo

i-e-b / skinnyjson Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 1.78 MB

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

License: BSD 3-Clause "New" or "Revised" License

C# 100.00%
c-sharp json serialisation serialization interface-segregation-principle messaging production-ready

skinnyjson's Introduction

SkinnyJson

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

Nuget:

The default is usually ahead of the strong-named version. If you need an updated version of the Strong-Named package, please open a Github issue.

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

skinnyjson's People

Contributors

i-e-b avatar matthunt-goco avatar

Watchers

 avatar  avatar

Forkers

michael-stock

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.