Monday, December 24, 2012

JSV Format

Included as data serialization option with ServiceStack,
"JSV" is a optimized for speed and simplicity.

JSV Format:
"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"

C#: new MyClass { A=1, B=2, C=3, D=4 }
JSV: {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:

C#: new MyClass { Foo="Bar", Greet="Hello World!"} is serialized as
JSV: {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:

C#: new MyClass { Name = "Me, Junior" }
JSV: {Name:"Me, Junior"}

C#: new MyClass { Size = "2\" x 1\"" }
JSV: {Size:"2"" x 1"""}


So why bother? The answer is: performance.
When both ends of communication (i.e. client & server)
support more optimal format, it makes sense to use it.

No comments: