Instructions to convert JSON object to C# code
Step 0:
The keys which are present in the JSON object will be used to name variables, so name the keys accordingly.Step 1:
- Paste the JSON string in the input field and click on “Generate C# Classes” button.
- Once C# code is generated, it’ll be copied to clipboard automatically. First class will be named as Parent, you can rename it and use it in your project.
Step 2:
This website is a PWA (Progressive Web App). You can install this and open it directly from Launcher/Start menu.
JSON input:
{
"user": [
{
"name": "Admin",
"age": 36
}
]
}
Output with Newtonsoft:
public
class
Parent
{
[JsonProperty("user")]
private
List<User> _userList;
public
List<User> GetUserList()
{
return _userList;
}
}
public class User
{
[JsonProperty("name")]
private string _name;
[JsonProperty("age")]
private int _age;
public string GetName()
{
return _name;
}
public int GetAge()
{
return _age;
}
}
Output without Newtonsoft:
[System.Serializable]
public class Parent
{
public List<User> user;
}
[System.Serializable]
public class User
{
public string name;
public int age;
}