Avatar ·

How to deserialize JSON to a dynamic object in C#?

Hello everyone! I'm new to C# and working with JSON data from an external API. The JSON structure can change, and I don't want to create a separate class for each case. For example, I have this JSON:\n\n```json\n{\n "name": "John",\n "age": 30,\n "address": {\n "city": "Moscow",\n "street": "Tverskaya"\n }\n}\n```\n\nBut sometimes another JSON comes:\n\n```json\n{\n "product": "Laptop",\n "price": 1200,\n "features": ["SSD", "16GB RAM"]\n}\n```\n\nI tried using `JavaScriptSerializer` and `JsonConvert.DeserializeObject`, but they require a predefined class. For example:\n\n```csharp\nvar result = JsonConvert.DeserializeObject(jsonString);\n```\n\nBut if I don't know the structure in advance, how do I work with such data? I heard about `dynamic` in C#, but I don't understand how to apply it.