Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add markdown Readme for System.Text.Json #69015

Merged
merged 11 commits into from
Jun 10, 2022
2 changes: 2 additions & 0 deletions src/libraries/System.Text.Json/src/System.Text.Json.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ System.Text.Json.Nodes.JsonNode
System.Text.Json.Nodes.JsonArray
System.Text.Json.Nodes.JsonObject
System.Text.Json.Nodes.JsonValue</PackageDescription>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
Expand Down Expand Up @@ -319,6 +320,7 @@ System.Text.Json.Nodes.JsonValue</PackageDescription>
<Compile Include="System\Text\Json\Writer\Utf8JsonWriter.WriteValues.UnsignedNumber.cs" />
<Compile Include="System\ReflectionExtensions.cs" />
<Compile Include="$(CommonPath)System\Obsoletions.cs" Link="Common\System\Obsoletions.cs" />
<None Include="readme.md" Pack="true" PackagePath="\"/>
eiriktsarpalis marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
Expand Down
54 changes: 54 additions & 0 deletions src/libraries/System.Text.Json/src/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
## About
eiriktsarpalis marked this conversation as resolved.
Show resolved Hide resolved

Provides high-performance and low-allocating types that serialize objects to JavaScript Object Notation (JSON) text and deserialize JSON text to objects, with UTF-8 support built-in. Also provides types to read and write JSON text encoded as UTF-8, and to create an in-memory document object model (DOM), that is read-only, for random access of the JSON elements within a structured view of the data.

The `System.Text.Json` library is built-in as part of the shared framework for .NET Core 3.0+ and .NET 5+. You only need to install it as a package for earlier .NET Core versions or other target frameworks.

For more information, see [JSON serialization and deserialization in .NET](https://docs.microsoft.com/dotnet/standard/serialization/system-text-json-overview).

## Example

The following example shows how to serialize and deserialize JSON.

```
using System;
using System.Text.Json;

class Person
{
public string Name { get; set; }
public string Surname { get; set; }
public DateTime BirthDate { get; set; }
}

class Program
{
static void Main()
{
var person = new Person();
person.Name = "John";
person.Surname = "Smith";
person.BirthDate = new DateTime(1988, 4, 20);

// Serialize object to JSON:
string jsonString = JsonSerializer.Serialize(person);
Console.WriteLine(jsonString);
// Output:
// {"Name":"John","Surname":"Smith","BirthDate":"1988-04-20T00:00:00"}

// Deserialize object from JSON:
Person personDeserialized = JsonSerializer.Deserialize<Person>(jsonString);
Console.WriteLine($"Name: {personDeserialized.Name}");
Console.WriteLine($"Surname: {personDeserialized.Surname}");
Console.WriteLine($"BirthDate: {personDeserialized.BirthDate}");
}
}
```

## Commonly Used Types

- [System.Text.Json.JsonSerializer](https://docs.microsoft.com/dotnet/api/system.text.json.jsonserializer)
- [System.Text.Json.JsonDocument](https://docs.microsoft.com/dotnet/api/system.text.json.jsondocument)
- [System.Text.Json.JsonElement](https://docs.microsoft.com/dotnet/api/system.text.json.jsonelement)
- [System.Text.Json.Utf8JsonWriter](https://docs.microsoft.com/dotnet/api/system.text.json.utf8jsonwriter)
- [System.Text.Json.Utf8JsonReader](https://docs.microsoft.com/dotnet/api/system.text.json.utf8jsonreader)
MSDN-WhiteKnight marked this conversation as resolved.
Show resolved Hide resolved