Hi everyone! Hope everything is well at your end. In my last part I have discussed about some of online tools for json converter to POJO classes. If you have not read it earlier you can find the link here .
Last time I have mentioned online tools today I am going to mention visual studio hacks and VS code extension to accomplish same task.
VS code extension
Json to JS convertor
What : This VS code extension converts JSON string into JS object.
How : Select JSON string and press Ctrl + Shift + J or press Ctrl + Shift + P and type Convert JSON into JS object.
JSON to JS object
What : This VS code extension converts JSON string to JS object. It converts snake case keys to camel case keys while converting to object.
How : Select JSON string and press Ctrl + Shift + P and type JSON to JS object.
Visual Studio
You can convert JSON string to C# POJO objects using an easy Visual studio hack.
What: Visual Studio provides a paste special option to convert JSON strings into C# POJO classes.
How: Copy JSON string and in visual studio open project or solution and then in Edit tab -> select Paste Special -> Paste JSON as Object.
Sample JSON string
{
"student": {
"name": "Test",
"degree": "IT",
"subjects": [{
"name" : "Computer Science",
"mark": 95
},
{
"name" : "Maths",
"mark": 98
}]
}
}
And then once you click on Paste JSON as Object menu, the above JSON object is converted into class and pasted as classes in the file.
namespace ClassLibrary1
{
public class Rootobject
{
public Student student { get; set; }
}
public class Student
{
public string name { get; set; }
public string degree { get; set; }
public Subject[] subjects { get; set; }
}
public class Subject
{
public string name { get; set; }
public int mark { get; set; }
}
}
Visual Studio Tool
JSON to C# tool
What : This tool will convert JSON string to C# classes and also add JSONProperty Attribute to represent property when they are serialized to JSON.
How : Install JSON to C# tool and then from Tools menu -> JSON to C# menu -> Paste JSON string -> Generate
OR Copy Json data -> right click on project folder and Generate classes from JSON.
That's all for today, Stay tuned for next time when I will discuss tools for JSON validation.
Happy Coding!...