Development · Native API migration preview · Coverage validation in progress Published release →

API Browser

Module

System.Data.Json

module System.Data.Json

JSON values and serialization

JsonValue and its object, array and scalar forms represent JSON data. JsonSerializer provides parsing, writing and supported value mapping, with JsonError describing syntax, type, field, size and mapping failures.

See JSON for supported shapes and limits, and error payloads for inspecting failures. System.Web.Http.Json adds HTTP integration on top of these contracts.

JsonObject implements Map<string, JsonValue>. Use value["name"] for an existing field; a missing field causes a terminal Fault. Prefer Find (Some/None) or Field (typed JSON error) when absence is expected. A present JsonNull remains a node, distinct from absence. Keys and pair iteration are shallow, insertion-ordered snapshots retaining original node references. Mutation still uses Add, which rejects duplicates and reports the container quota through Result; JsonObject does not implement MutableMap yet.

JsonArray implements Sequence<JsonValue>. Use array[index] for known valid indices, or Item(index) for a recoverable InvalidIndex result. Negative and past-end indexer accesses cause a terminal Fault. for iteration captures a shallow ordered snapshot: later additions are excluded, while child nodes remain shared. Count and indexing read the current array. Mutation continues to use quota-aware Add; MutableSequence is not implemented.

Use node.ToJsonString() for compact JSON text. For readable output, pass a JsonSerializerOptions with WriteIndented = true. The same option is available on JsonSerializer.SerializeNode and Serialize, including stream overloads. Formatting and limits.

Development byte output: SerializeToUtf8Bytes(value[, options]) returns an owned byte array. HTTP content and stream serialization use the same bounded UTF-8 writer, avoiding intermediate document strings. Stream input still parses through text. See byte output and ownership.

Development parsing borrows the source string's UTF-8 bytes and creates owned text only for string values, names and number lexemes. Escaped tokens still need scratch storage. DeserializeNode and typed Deserialize also accept ReadOnlySlice<byte>; buffered HTTP content uses these byte overloads without a document string. Stream deserialization still decodes full text; incremental readers remain future work. See byte input and errors.

Types

12 items
JsonArray A JSON array with a read-only sequence view.
JsonBoolean Immutable boolean-valued JSON node.
JsonCommentHandling Controls how JSON comments are read.
JsonDocumentOptions Controls JSON document parsing, independently of output formatting.
JsonError Expected JSON syntax, resource, lookup, conversion or I/O failure. Match cases to inspect causes; diagnostic strings are not stable identifiers.
JsonNull Explicit JSON null node, distinct from a missing member.
JsonNumber Immutable validated JSON number token retaining its exact spelling without floating-point conversion.
JsonObject A JSON object with ordinal field names and a read-only map view.
JsonSerializer Provisional DOM codec and bounded nested object mapper supporting strings and borrowed UTF-8 streams.
JsonSerializerOptions Controls JSON output formatting.
JsonString Immutable string-valued JSON node.
JsonValue Closed abstract root of the provisional JSON DOM.