JSV Format

Demis Bellot edited this page Jun 22, 2016 · 4 revisions

JSV Text Format (JSON + CSV)

Type Serializer uses a hybrid CSV-style escaping + JavaScript-like text-based format that is optimized for both size and speed. I'm naming this JSV-format (i.e. JSON + CSV)

In many ways it is similar to JavaScript, e.g. any List, Array, Collection of ints, longs, etc are stored in exactly the same way, i.e: [1,2,3,4,5]

Any IDictionary is serialized like JavaScript, i.e: {A:1,B:2,C:3,D:4}

Which also happens to be the same as C# POCO class with the values

new MyClass { A=1, B=2, C=3, D=4 }

{A:1,B:2,C:3,D:4}

JSV is white-space significant, which means normal string values can be serialized without quotes, e.g:

new MyClass { Foo="Bar", Greet="Hello World!"} is serialized as:

{Foo:Bar,Greet:Hello World!}

CSV escaping

Any string with any of the following characters: []{}," is escaped using CSV-style escaping where the value is wrapped in double quotes, e.g:

new MyClass { Name = "Me, Junior" } is serialized as:

{Name:"Me, Junior"}

A value with a double-quote is escaped with another double quote e.g:

new MyClass { Size = "2\" x 1\"" } is serialized as:

{Size:"2"" x 1"""}

JSV Serialiers

C#/.NET JSV Serializer

The JSV Format is available in ServiceStack.Text .NET's TypeSerializer, e.g:

var jsv = TypeSerializer.SerializeToString(model);
var dto = TypeSerializer.DeserializeFromString<Poco>(jsv);

Or via the ToJsv/FromJsv extension methods, e.g:

var jsv = model.ToJsv();
var dto = jsv.FromJsv<Poco>();

.NET JsvServiceClient

Thanks to the performance benefits of JSV's CSV-style escaping, the JsvServiceClient is our fastest text-based serializer for .NET:

var client = new JsvServiceClient(baseUrl);
var response = client.Get(new Hello { Name = "World" });

JavaScript JSV Serialier

A JavaScript JSV parser is also available from JSV.js:

var jsv = JSV.stringify(model);
var dto = JSV.parse(jsv);

JavaScript JsvServiceClient

JSV.js also includes the JsvServiceClient for consuming JSV Services:

var client = new JsvServiceClient(baseUrl);
client.getFromService("Hello", { name: "World" }, function(r) {
});

Resources

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.