Serializing and Deserializing JSON


Came across a few little extensions in Visual Studio Code Extensions Marketplace recently that has and will further save me considerable time when I need to work with JSON. Thought I’d share it as JSON is everywhere nowadays and serializing/deserializing them are frequently asked topics on Stack Overflow and other online forums but with most of the answers there are very manual and seldom cover complex collections.

These extension are ‘shortcuts’ that automatically generates code for you in the language of your choice when you provide the JSON input. And trust me, there’s a fair bit of typing it will save (hours), especially for the more complicated nested JSON objects and their collections. It supports all the popular languages like C#, C++,Python, Java, JavaScript, etc.

To use any of the extensions,  just download, install and configure within Visual Studio Code, the simplicity of each means you’ll be up and running in under a few minutes. All the steps needed is documented in the Marketplace so I’ll skip that and show you how they are used.

The first one is JSON Parse & Stringify. This helps you ‘easily switch between stringified JSON and JavaScript objects’. So it convert something like this:

Serializing and de-serializing JSON

to something like this below so your typical libraries like JSON.Newtonsoft in .Net can use.

Serializing and de-serializing JSON

You can watch this video below to see how it works.

The second one is Paste JSON as Code. It converts JSON like the first screenshot to actual programable code you can use like this below in C#.

Serializing and de-serializing JSON

Unlike the shortcuts on some IDEs like Visual Studio (Paste as JSON), this creates all the objects and methods you’ll need to work with your JSON collection. You can see how it works on this video below.

For those that can’t install Visual Studio Code or access the Marketplace (workplace policy-firewalls), there’s also an online version:

Happy programming. This will save you hours.








Leave a Reply