JSON Standard Business Card

Front:

Doughnuts. Is there anything they can't do?

Back:

Just because I don't care doesn't mean I don't understand.

Awesome.

I think it is pretty cool that the entire standard can be put on the back of a business card (and a quarter of that is for defining what a number is!).

From here.

Implicit Conversions and LINQ to JSON

I have been doing a lot of work with Json.NET recently and have really been using LINQ to JSON in anger for the first time.

Pretty quickly I became annoyed with having to constantly wrap .NET primitive objects (int, long, string, DateTime, etc) in JValue whenever they’re added to a JSON object or array.

JObject moss = new JObject();
moss["FirstName"] = new JValue("Maurice");
moss["LastName"] = new JValue("Moss");
moss["BirthDate"] = new JValue(new DateTime(1977, 12, 30));
moss["Department"] = new JValue("IT");
moss["JobTitle"] = new JValue("Support");
 
Console.WriteLine(moss.ToString());
//{
//  "FirstName": "Maurice",
//  "LastName": "Moss",
//  "BirthDate": "\/Date(252241200000+1300)\/",
//  "Department": "IT",
//  "JobTitle": "Support"
//}

Gross. Why?

For all the LINQy goodness I’ve added to Json.NET to work everything has to inherit from a common object: JToken. Container objects (JObject and JArray) inherit from JToken and all their child values must also be JTokens. For that reason JObject implements IDictionary<string, JToken> and JArray implements IList<JToken>.

Because the containers only allow JTokens, basic primitive values need to be wrapped in an object which inherits from JToken: JValue.

Each time we want to set a value on an object or add a value to an array it has to be manually wrapped in a JValue. Ugly!

Implicit Conversions

The solution is really simple: implicit conversions. Adding an implicit conversion operator allows .NET to automatically convert from the primitive to JValue without any of the above unpleasantness.

///<summary>
/// Performs an implicit conversion from <see cref="String"/> to <see cref="JToken"/>.
///</summary>
///<param name="value">The value to create a <see cref="JValue"/> from.</param>
///<returns>The <see cref="JValue"/> initialized with the specified value.</returns>
public static implicit operator JToken(string value)
{
  return new JValue(value);
}

And here is the new end user experience:

JObject jen = new JObject();
jen["FirstName"] = "Jen";
jen["LastName"] = "Barber";
jen["BirthDate"] = new DateTime(1978, 3, 15);
jen["Department"] = "IT";
jen["JobTitle"] = "Manager";

Much better I think you’ll agree. I only wish I had done it earlier [:)]

Backstage With Office 2010 Website Live!

The past two weeks I have been working long hours with a small band from Intergen on the Backstage With Office 2010 website. I can happily say that today Backstage went live with the unveiling of Microsoft Office 2010!

Backstage is full of videos from the Office 2010 team who go behind the scenes of Office development and talk about what they have been busy working on since 2007. The main Backstage website is 100% Silverlight shows off lots of neat features.

  • 100% Silverlight design
  • Smooth streaming – videos will scale from HD for awesome broadband connections down to speed optimized resolutions for mobile devices
  • Embedded social links to those sites all the cool kids are using (Twitter, Facebook, Delicious, Digg, Live)
  • Deep linking directly to videos
  • Commenting and rating videos, video view counts

Uh, no, they’re saying "Boo-urns, Boo-urns."

As well as the main site we have created an RSS feed of recently added videos. Not only can you subscribe to it an RSS reader but the feed also works with iTunes and other video podcast clients.

I was saying "Boo-urns."

Finally visiting mobile users will automatically be redirect to an HTML mobile version of the site, complete with low resolution videos for 3G mobile devices. It looks fantastic on my iPhone.

Fat Tony is a cancer on this fair city! He is the cancer and I am the…uh…what cures cancer?

Its been a crazy ride getting everything done in time for the launch but I think the end result was worth it. Check out Backstage With Office 2010 here.