Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Text.​Json.​Nodes.​JsonObject

Assembly: System.Text.Json

Inheritance: object → JsonNode → JsonObject

Implemented Interfaces

Represents a mutable JSON object.

Properties

public int
Count
Gets the number of elements contained in <see cref="T:System.Text.Json.Nodes.JsonObject" /> .
public JsonNode
Item
public JsonNode
Item
public JsonNodeOptions?
Options
Gets the options to control the behavior.
public JsonNode
Parent
Gets the parent <see cref="T:System.Text.Json.Nodes.JsonNode" /> . If there is no parent, <see langword="null" /> is returned. A parent can either be a <see cref="T:System.Text.Json.Nodes.JsonObject" /> or a <see cref="T:System.Text.Json.Nodes.JsonArray" /> .
public JsonNode
Root
Gets the root <see cref="T:System.Text.Json.Nodes.JsonNode" /> .

Methods

public void
Add​(Collections.​Generic.​KeyValuePair<​string, JsonNode> property)
Adds the specified property to the <see cref="T:System.Text.Json.Nodes.JsonObject" /> .
property The KeyValuePair structure representing the property name and value to add to the <see cref="T:System.Text.Json.Nodes.JsonObject" /> .
public void
Add​(string propertyName, JsonNode? value)
Adds an element with the provided property name and value to the <see cref="T:System.Text.Json.Nodes.JsonObject" /> .
propertyName The property name of the element to add.
value The value of the element to add.
public bool
TryAdd​(string propertyName, JsonNode? value)
Adds an element with the provided name and value to the <see cref="T:System.Text.Json.Nodes.JsonObject" /> , if a property named <paramref name="propertyName" /> doesn't already exist.
Returns <see langword="true" /> if the property didn't exist and the element was added; otherwise, <see langword="false" /> .
propertyName The property name of the element to add.
value The value of the element to add.
public bool
TryAdd​(string propertyName, JsonNode? value, Int32& index)
public void
Clear​()
Removes all elements from the <see cref="T:System.Text.Json.Nodes.JsonObject" /> .
public bool
ContainsKey​(string propertyName)
Determines whether the <see cref="T:System.Text.Json.Nodes.JsonObject" /> contains an element with the specified property name.
Returns <see langword="true" /> if the <see cref="T:System.Text.Json.Nodes.JsonObject" /> contains an element with the specified property name; otherwise, <see langword="false" /> .
propertyName The property name to locate in the <see cref="T:System.Text.Json.Nodes.JsonObject" /> .
public static JsonObject
Create​(JsonElement element, JsonNodeOptions? options = null)
Initializes a new instance of the <see cref="T:System.Text.Json.Nodes.JsonObject" /> class that contains properties from the specified <see cref="T:System.Text.Json.JsonElement" /> .
Returns The new instance of the <see cref="T:System.Text.Json.Nodes.JsonObject" /> class that contains properties from the specified <see cref="T:System.Text.Json.JsonElement" /> .
element The <see cref="T:System.Text.Json.JsonElement" /> .
options Options to control the behavior.
GetAt​(int index)
Gets the property of the specified index.
Returns The property at the specified index as a key/value pair.
index The zero-based index of the pair to get.
GetEnumerator​()
Returns an enumerator that iterates through the <see cref="T:System.Text.Json.Nodes.JsonObject" /> .
Returns An enumerator that iterates through the <see cref="T:System.Text.Json.Nodes.JsonObject" /> .
public int
IndexOf​(string propertyName)
Determines the index of a specific property name in the object.
Returns The index of <paramref name="propertyName" /> if found; otherwise, -1.
propertyName The property name to locate.
public void
Insert​(int index, string propertyName, JsonNode? value)
Inserts a property into the object at the specified index.
index The zero-based index at which the property should be inserted.
propertyName The property name to insert.
value The JSON value to insert.
public bool
Remove​(string propertyName)
Removes the element with the specified property name from the <see cref="T:System.Text.Json.Nodes.JsonObject" /> .
Returns <see langword="true" /> if the element is successfully removed; otherwise, <see langword="false" /> .
propertyName The property name of the element to remove.
public void
RemoveAt​(int index)
Removes the property at the specified index.
index The zero-based index of the item to remove.
public void
SetAt​(int index, string propertyName, JsonNode? value)
Sets a new property at the specified index.
index The zero-based index of the property to set.
propertyName The property name to store at the specified index.
value The JSON value to store at the specified index.
public void
SetAt​(int index, JsonNode value)
Sets a new property value at the specified index.
index The zero-based index of the property to set.
value The JSON value to store at the specified index.
public bool
TryGetPropertyValue​(string propertyName, JsonNode&? jsonNode)
public bool
TryGetPropertyValue​(string propertyName, JsonNode&? jsonNode, Int32& index)
public void
WriteTo​(Utf8JsonWriter writer, JsonSerializerOptions? options = null)
Writes the <see cref="T:System.Text.Json.Nodes.JsonNode" /> into the provided <see cref="T:System.Text.Json.Utf8JsonWriter" /> as JSON.
writer The <see cref="T:System.Text.Json.Utf8JsonWriter" /> .
options Options to control the serialization behavior.
public JsonArray
AsArray​()
Inherited from JsonNode
Casts to the derived <see cref="T:System.Text.Json.Nodes.JsonArray" /> type.
Returns A <see cref="T:System.Text.Json.Nodes.JsonArray" /> .
public JsonObject
AsObject​()
Inherited from JsonNode
Casts to the derived <see cref="T:System.Text.Json.Nodes.JsonObject" /> type.
Returns A <see cref="T:System.Text.Json.Nodes.JsonObject" /> .
public JsonValue
AsValue​()
Inherited from JsonNode
Casts to the derived <see cref="T:System.Text.Json.Nodes.JsonValue" /> type.
Returns A <see cref="T:System.Text.Json.Nodes.JsonValue" /> .
public JsonNode
DeepClone​()
Inherited from JsonNode
Creates a new instance of the <see cref="T:System.Text.Json.Nodes.JsonNode" /> class. All child nodes are recursively cloned.
Returns A new cloned instance of the current node.
public int
GetElementIndex​()
Inherited from JsonNode
Returns the index of the current node from the parent <see cref="T:System.Text.Json.Nodes.JsonArray" /> .
Returns The index of the current node.
public string
GetPath​()
Inherited from JsonNode
Gets the JSON path.
Returns The JSON Path value.
public string
GetPropertyName​()
Inherited from JsonNode
Returns the property name of the current node from the parent object.
Returns The property name of the current node.
public JsonValueKind
GetValueKind​()
Inherited from JsonNode
Returns the <see cref="T:System.Text.Json.JsonValueKind" /> of the current instance.
Returns The json value kind of the current instance.
public T
GetValue​()
Inherited from JsonNode
Gets the value for the current <see cref="T:System.Text.Json.Nodes.JsonValue" /> .
Returns A value converted from the <see cref="T:System.Text.Json.Nodes.JsonValue" /> instance.
public void
ReplaceWith​(T value)
Inherited from JsonNode
Replaces this node with a new value.
value The value that replaces this node.
public string
ToJsonString​(JsonSerializerOptions? options = null)
Inherited from JsonNode
Converts the current instance to a string in JSON format.
Returns The JSON representation of the current instance.
options Options to control the serialization behavior.
public string
ToString​()
Inherited from JsonNode
Gets a string representation for the current value appropriate to the node type.
Returns A string representation for the current value appropriate to the node type.
public bool
Equals​(object obj)
Inherited from object
protected void
Finalize​()
Inherited from object
public int
GetHashCode​()
Inherited from object
public Type
GetType​()
Inherited from object
protected object
MemberwiseClone​()
Inherited from object