JetBrains Rider 2023.2 Help

Generate C# classes from JSON

JetBrains Rider 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" } ] }

JetBrains Rider 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; } }
  1. 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.

  2. Place the caret in a C# file where class declarations are allowed.

  3. Press Control+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: 01 September 2023