JetBrainsRider lets you generate C# classes based on existing JSON. For example, from the following JSON object:
{ "Description": "Remove braces", "Scope": "editor", "IdeActions": [ { "Ide": "visual_assist", "Id": "BracesRemove" }, { "Ide": "intellij", "Id": "Unwrap" } ] }
JetBrainsRider will create classes that describe the structure of this object, which you can then use to read JSON files with the same object structure.
public class RootObject { public string Description { get; set; } public string Scope { get; set; } public IdeActions[] IdeActions { get; set; }}public class IdeActions { public string Ide { get; set; } public string Id { get; set; }}
Copy a valid JSON to the clipboard — this can be the whole text of a JSON file or one or more objects in the JSON format. If you copy a part of JSON file, make sure that the copy is a valid JSON that starts and ends with
{...}
or[...]
on the same level.Place the caret in a C# file where class declarations are allowed.
Press Ctrl+Shift+A or choose Help | Find Action from the main menu. In the popup that opens, start typing
Paste Special: JSON as Classes
, select the corresponding item and press Enter.
Last modified: 11 February 2024