Fluent JSON creation (and Knockout)

Oct 24, 2011 at 8:02 PM
Edited Nov 1, 2011 at 8:55 PM

I created a Fluent JSON library for building Knockout view models (or any other JSON object) built on top of JSON.NET. I thought I would share:

http://github.com/paultyng/FluentJson.NET

The FluentJSON component allows you to create JSON in a Razor view like this (note the Knockout extension methods):

@JsonObject.Create()
    .AddProperty("name", "value")
    .AddProperty("childObject", c => {
        .AddProperty("childProperty", "value2")
    })
    .AddObservable("knockoutProperty", 123)

This would produce JSON similar to this:

 

{"name":"value","childObject":{"childProperty":"value2"},"knockoutProperty":ko.observable(123)}

 

The Knockout methods are added via extension methods and other things can easily extend as well.  Please feel free to comment / criticize over at GitHub.

Paul