how to add new property to json?
I have following code:
I need to add following property to each property in
propertyProperties
: "additionalProperties": true
but I don't understand how to do it correctly6 Replies
I tried this:
but it doesn't work correctly because of
is should be this:
{
"properties": {
"aircraft": {
"type": "object",
"properties": {
"aircraftType": {
"type": "string",
"example": "77W"
},
"aircraftNumber": {
"type": "string",
"example": "72348"
}
}
},
not this:
[
{
"Value": {
"type": "object",
"properties": {
"aircraftType": {
"type": "string",
"example": "77W"
},
"aircraftNumber": {
"type": "string",
"example": "72348"
}
}
},
"Name": "aircraft",
"additionalProperties": false
},
hmm this works:
but looks ugly asf
any reason you are not serializing to a known type in the first place?
json contains unknown structure for me, I just need to find property that has
generateModelClassName
and do some work with propertiesin that case, just identify the
JsonObject
you wish to add something to, and use .Add(string, JsonValue)
.
also, your example seems... really weird
as your "it should look like this" doesnt contain the property you wanted to adddo not deseiralize to JsonDocument
deseiralize directly to JsonObject instead
JsonNode.Parse Method (System.Text.Json.Nodes)
Parses text representing a single JSON value.