Online Tool of the Month – QuickType

I was recently working on a freelance project which required interaction with a 3rd party webservice that returned a JSON result.

While connecting to the service and fetching the data was a fairly trivial task, looking at the data being returned it was clear that a lot of POCO/DTO classes were going to be required.

Obviously these are easy to create but they are time consuming and prone to the odd typo. I then remembered a labour saving service called QuickType which would take the returned JSON and generate the C# code for me РI just needed to pull it into my project.

When you navigate to the QuickType site you are presented with some sample input data in the left panel and the resulting C# code in the main panel. There are also some options in the panel to the top right that we will need to tweak.

In the screenshot below I’ve pasted in some JSON which was generated by another online service called, oddly enough, JSON Generator¬†(I’ll probably feature this tool next month). I’ve also used the ‘Target Language’ dropdown to select C#, specified a Namespace and collection type to use (List<T>).

 

As you can see (notwithstanding the truncated lines which are an artefact of my screen capture tool), not only has QuickType generated the main Person class, it has detected and created the ‘Friend’ class along with some serialisation and conversion classes (with methods inside of which can be extracted and used as required – or discarded).

It has also added JsonProperty attributes to the properties (assuming NewtonSoft.Json) and provided usage details

 

Now obviously there is no voodoo at work here – creating these classes is pretty trivial – but this is a great time saving tool which can free up your development time to actually develop instead of churning out this mundane code.