METHOD

JsonElement.Clone

Creates an element that remains usable after the originating JsonDocument is disposed. Copying the struct alone does not detach it from its document.

Formal Syntax & Structure

csharp syntaxcsharp
element.Clone()

Working Example

Example Snippetcsharp
using System;using System.IO;using System.Collections.Generic;using System.Text.Json;JsonElement value; using(var d = JsonDocument.Parse("[1,2]")) { value = d.RootElement.Clone(); } Console.WriteLine(value.GetArrayLength()); // 2
C# & .NET Reference