---
# System prepended metadata

title: System.Text.Json Json 文字列を見やすく整形する。 2022-08-02
tags: [System.Text.Json]

---

---
lang: ja-jp
breaks: true
---
# System.Text.Json Json 文字列を見やすく整形する。 2022-08-02

```csharp!
        string json;
        using (var stream = new MemoryStream())
        {
            JsonWriterOptions jsonWriterOptions = new()
            {
                Indented = true,
                SkipValidation = true,
                Encoder = JavaScriptEncoder.Create(UnicodeRanges.All),
            };
            using (Utf8JsonWriter writer = new Utf8JsonWriter(stream, jsonWriterOptions))
            {
                using (JsonDocument jsonDocument = JsonDocument.Parse(jsonString))
                {
                    jsonDocument.WriteTo(writer);
                    writer.Flush();
                }
                json = Encoding.UTF8.GetString(stream.ToArray());
            }
        }

Debug.WriteLine("------------------------");
Debug.WriteLine(json);
Debug.WriteLine("------------------------");
```

###### tags: `System.Text.Json`
