C#C
C#2y ago
SWEETPONY

how to add new property to json?

I have following code:
var schema = File.ReadAllText("legData.json");
var result = Parse(schema);

Console.WriteLine(result);

string Parse(string jsonSchema)
{
    using var document = JsonDocument.Parse(jsonSchema);
    var root = document.RootElement;

    if(!root.TryGetProperty("properties", out _))
        return "";

    var properties = root.GetProperty("properties").EnumerateObject();
    var property = properties.FirstOrDefault(prop => prop.Value.TryGetProperty("generateModelClassName", out _));
    var propertyProperties = property.Value.GetProperty("properties");
    var formatted = $$"""{"properties": {{propertyProperties}}}""";
    return formatted;
}


I need to add following property to each property in
propertyProperties
:
"additionalProperties": true

but I don't understand how to do it correctly
Was this page helpful?