Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

System.Text.Json.JsonSerializer: practical reference

System.Text.Json.JsonSerializer: practical reference: JsonSerializer maps .NET values to JSON and back according to type contracts.

Version: .NET API; verified against .NET 10 reference surface

Syntax

System.Text.Json.JsonSerializer /* select a documented member or constructor */

JsonSerializer maps .NET values to JSON and back according to type contracts.

Use it for DTO models with explicit options and a source-generated context under AOT.

Default names, null handling, and fields do not always match an external contract.

Invalid JSON throws JsonException; cycles require explicit configuration.

The complete program actually uses System.Text.Json.JsonSerializer; its exact expected stdout is [1,2].

Examples

using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;

Console.WriteLine(JsonSerializer.Serialize(new[] { 1, 2 }));

Result

[1,2]

The complete program actually uses `System.Text.Json.JsonSerializer`; its exact expected stdout is `[1,2]`.

Sources