9 instantiations of JsonElement
Microsoft.AspNetCore.Components.WebAssembly.Server (1)
System.Text.Json (8)
921 references to JsonElement
aspire (19)
DotNetCliRunner.cs (17)
66var rootElement = jsonDocument.RootElement;
68if (!rootElement.TryGetProperty("Properties", out var properties))
73if (!properties.TryGetProperty("IsAspireHost", out var isAspireHostElement))
83if (rootElement.TryGetProperty("Items", out var items))
86if (items.TryGetProperty("PackageReference", out var packageReferences))
88foreach (var packageRef in packageReferences.EnumerateArray())
90if (packageRef.TryGetProperty("Identity", out var identity) &&
92packageRef.TryGetProperty("Version", out var version))
101if (aspireHostingVersion == null && items.TryGetProperty("AspireProjectOrPackageReference", out var aspireProjectOrPackageReferences))
103foreach (var aspireRef in aspireProjectOrPackageReferences.EnumerateArray())
105if (aspireRef.TryGetProperty("Identity", out var identity) &&
107aspireRef.TryGetProperty("Version", out var version))
117if (aspireHostingVersion == null && properties.TryGetProperty("AspireHostingSDKVersion", out var aspireHostingSdkVersionElement))
724var searchResultsArray = document.RootElement.GetProperty("searchResult");
726foreach (var sourceResult in searchResultsArray.EnumerateArray())
729var sourcePackagesArray = sourceResult.GetProperty("packages");
731foreach (var packageResult in sourcePackagesArray.EnumerateArray())
Aspire.Azure.Npgsql (6)
Aspire.Azure.Npgsql.EntityFrameworkCore.PostgreSQL (6)
Aspire.Hosting (5)
Aspire.Hosting.PostgreSQL.Tests (1)
Aspire.Hosting.Seq.Tests (2)
Aspire.Hosting.Tests (32)
Diagnostics.FunctionalTests (2)
dotnet-openapi (1)
dotnet-user-jwts (8)
IdentitySample.PasskeyConformance (5)
IdentitySample.PasskeyUI (2)
JwtBearerSample (1)
Microsoft.AspNetCore.Authentication (4)
Microsoft.AspNetCore.Authentication.OAuth (24)
Microsoft.AspNetCore.Authentication.OpenIdConnect (1)
Microsoft.AspNetCore.Authentication.Test (2)
Microsoft.AspNetCore.Authentication.Twitter (5)
Microsoft.AspNetCore.Components.Endpoints.Tests (15)
Microsoft.AspNetCore.Components.Server (6)
Microsoft.AspNetCore.Components.Server.Tests (2)
Microsoft.AspNetCore.Components.Web (36)
Microsoft.AspNetCore.Components.Web.Tests (51)
Microsoft.AspNetCore.Components.WebAssembly (5)
Microsoft.AspNetCore.Components.WebAssembly.Server (12)
Microsoft.AspNetCore.Components.WebView (6)
IpcCommon.cs (6)
19public static bool TryDeserializeIncoming(string message, out IncomingMessageType messageType, out ArraySegment<JsonElement> args)
22public static bool TryDeserializeOutgoing(string message, out OutgoingMessageType messageType, out ArraySegment<JsonElement> args)
37private static bool TryDeserialize<T>(string message, out T messageType, out ArraySegment<JsonElement> args)
44var parsed = (JsonElement[])JsonSerializer.Deserialize(messageAfterPrefix, typeof(JsonElement[]), JsonSerializerOptionsProvider.Options);
46args = new ArraySegment<JsonElement>(parsed, 1, parsed.Length - 1);
Microsoft.AspNetCore.Diagnostics.Tests (10)
Microsoft.AspNetCore.Grpc.JsonTranscoding (2)
Microsoft.AspNetCore.Grpc.JsonTranscoding.Tests (7)
Microsoft.AspNetCore.Http.Abstractions.Tests (1)
Microsoft.AspNetCore.Http.Extensions (1)
Microsoft.AspNetCore.Http.Extensions.Tests (9)
Microsoft.AspNetCore.Identity (5)
Microsoft.AspNetCore.Identity.FunctionalTests (106)
Microsoft.AspNetCore.Identity.Test (5)
Microsoft.AspNetCore.JsonPatch.SystemTextJson (7)
Microsoft.AspNetCore.JsonPatch.SystemTextJson.Tests (1)
Microsoft.AspNetCore.Mvc.FunctionalTests (3)
Microsoft.AspNetCore.Mvc.ViewFeatures (6)
Microsoft.AspNetCore.Server.HttpSys.FunctionalTests (1)
Microsoft.AspNetCore.SignalR.Client.FunctionalTests (1)
Microsoft.AspNetCore.SignalR.Tests (4)
Microsoft.CodeAnalysis.EditorFeatures (8)
Microsoft.CodeAnalysis.ExternalAccess.Xaml (2)
Microsoft.CodeAnalysis.Features (1)
Microsoft.CodeAnalysis.LanguageServer.Protocol (25)
Microsoft.CodeAnalysis.LanguageServer.Protocol.UnitTests (5)
Microsoft.CodeAnalysis.LanguageServer.UnitTests (2)
Microsoft.CodeAnalysis.Workspaces.MSBuild (2)
Microsoft.CommonLanguageServerProtocol.Framework.Package (6)
Microsoft.DotNet.Arcade.Sdk (3)
Microsoft.Extensions.AI (7)
Microsoft.Extensions.AI.Abstractions (41)
Functions\AIFunctionFactory.cs (18)
92/// invocation directly if the object is already of a compatible type. Otherwise, if the argument is a <see cref="JsonElement"/>, <see cref="JsonDocument"/>,
104/// By default, return values are serialized to <see cref="JsonElement"/> using <paramref name="options"/>'s
166/// invocation directly if the object is already of a compatible type. Otherwise, if the argument is a <see cref="JsonElement"/>, <see cref="JsonDocument"/>,
178/// Return values are serialized to <see cref="JsonElement"/> using <paramref name="serializerOptions"/> if provided,
255/// invocation directly if the object is already of a compatible type. Otherwise, if the argument is a <see cref="JsonElement"/>, <see cref="JsonDocument"/>,
267/// By default, return values are serialized to <see cref="JsonElement"/> using <paramref name="options"/>'s
339/// invocation directly if the object is already of a compatible type. Otherwise, if the argument is a <see cref="JsonElement"/>, <see cref="JsonDocument"/>,
351/// Return values are serialized to <see cref="JsonElement"/> using <paramref name="serializerOptions"/> if provided,
391/// Return values are serialized to <see cref="JsonElement"/> using <paramref name="options"/>'s
394/// <see cref="AIFunctionFactoryOptions.SerializerOptions"/>. If the argument is a <see cref="JsonElement"/>,
441/// invocation directly if the object is already of a compatible type. Otherwise, if the argument is a <see cref="JsonElement"/>, <see cref="JsonDocument"/>,
453/// By default, return values are serialized to <see cref="JsonElement"/> using <paramref name="options"/>'s
543public override JsonElement JsonSchema => FunctionDescriptor.JsonSchema;
544public override JsonElement? ReturnJsonSchema => FunctionDescriptor.ReturnJsonSchema;
711public JsonElement JsonSchema { get; }
712public JsonElement? ReturnJsonSchema { get; }
819JsonElement element => JsonSerializer.Deserialize(element, typeInfo),
1012return JsonElement.ParseValue(ref reader);
Microsoft.Extensions.AI.Abstractions.Tests (76)
Utilities\AIJsonUtilitiesTests.cs (43)
146JsonElement expected = JsonDocument.Parse("""
168JsonElement actual = AIJsonUtilities.CreateJsonSchema(typeof(MyPoco), serializerOptions: JsonContext.Default.Options);
176JsonElement expected = JsonDocument.Parse("""
211JsonElement actual = AIJsonUtilities.CreateJsonSchema(
225JsonElement expected = JsonDocument.Parse("""
261JsonElement actual = AIJsonUtilities.CreateJsonSchema(typeof(MyPoco), serializerOptions: JsonContext.Default.Options, inferenceOptions: inferenceOptions);
274JsonElement resolvedSchema = AIJsonUtilities.CreateFunctionJsonSchema(func.UnderlyingMethod, title: string.Empty);
301JsonElement expected = JsonDocument.Parse($$"""
337JsonElement resolvedSchema = AIJsonUtilities.CreateFunctionJsonSchema(func.UnderlyingMethod, title: string.Empty, description: string.Empty, inferenceOptions: inferenceOptions);
347JsonElement schemaParameters = func.JsonSchema.GetProperty("properties");
361JsonElement expected = JsonDocument.Parse($$"""
367JsonElement actualSchema = property.Value;
386JsonElement schema = AIJsonUtilities.CreateJsonSchema(typeof(object));
405JsonElement schema = AIJsonUtilities.CreateJsonSchema(testData.Type, serializerOptions: options, inferenceOptions: createOptions);
430JsonElement schema = AIJsonUtilities.CreateJsonSchema(typeof(AIContent), serializerOptions: options);
440JsonElement expectedSchema = JsonDocument.Parse("""
447JsonElement schema = AIJsonUtilities.CreateJsonSchema(typeof(MyEnumValue?), serializerOptions: JsonContext.Default.Options);
1039JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method.Method, inferenceOptions: new()
1061JsonElement schema = JsonDocument.Parse("""
1072JsonElement expectedSchema = JsonDocument.Parse("""
1088JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options);
1095JsonElement schema = JsonDocument.Parse("""
1106JsonElement expectedSchema = JsonDocument.Parse("""
1122JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options);
1129JsonElement schema = JsonDocument.Parse("""
1140JsonElement expectedSchema = JsonDocument.Parse("""
1157JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options);
1164JsonElement schema = JsonDocument.Parse("""
1176JsonElement expectedSchema = JsonDocument.Parse("""
1194JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options);
1201JsonElement schema = JsonDocument.Parse("""
1209JsonElement expectedSchema = JsonDocument.Parse("""
1221JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options);
1240JsonElement schema = AIJsonUtilities.CreateJsonSchema(testData.Type, serializerOptions: options, inferenceOptions: createOptions);
1258JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, transformOptions);
1292JsonElement schema = JsonDocument.Parse("{}").RootElement;
1305JsonElement schema = JsonDocument.Parse(invalidSchema).RootElement;
1315[JsonSerializable(typeof(JsonElement))]
1322private static bool DeepEquals(JsonElement element1, JsonElement element2)
1325return JsonElement.DeepEquals(element1, element2);
1333private static void AssertDeepEquals(JsonElement element1, JsonElement element2)
Microsoft.Extensions.AI.AzureAIInference (1)
Microsoft.Extensions.AI.AzureAIInference.Tests (6)
Microsoft.Extensions.AI.Evaluation.Safety (4)
Microsoft.Extensions.AI.Integration.Tests (7)
Microsoft.Extensions.AI.Ollama (8)
Microsoft.Extensions.AI.Ollama.Tests (4)
Microsoft.Extensions.AI.OpenAI (3)
Microsoft.Extensions.AI.OpenAI.Tests (8)
Microsoft.Extensions.AI.Tests (16)
Microsoft.Extensions.Configuration.Json (4)
Microsoft.JSInterop.Tests (3)
Microsoft.ML.GenAI.Phi (4)
Microsoft.ML.Tokenizers.Tests (29)
BpeTests.cs (25)
883JsonElement root = doc.RootElement;
884if (!root.TryGetProperty("model", out JsonElement modelElement) ||
886!modelElement.TryGetProperty("type", out JsonElement typeElement) ||
888!modelElement.TryGetProperty("vocab", out JsonElement vocabElement) ||
896if (modelElement.TryGetProperty("unk_token", out JsonElement unKnownElement))
901if (modelElement.TryGetProperty("continuing_subword_prefix", out JsonElement continuingSubwordPrefixElement))
906if (modelElement.TryGetProperty("end_of_word_suffix", out JsonElement endOfWordSuffixElement))
911if (modelElement.TryGetProperty("fuse_unknown_tokens", out JsonElement fuseUnknownTokensElement))
931private static IEnumerable<(string Token, int Id)> GetVocabulary(JsonElement vocabElement)
939private static IEnumerable<string> GetMerges(JsonElement modelElement)
941if (modelElement.TryGetProperty("merges", out JsonElement mergesElement) && mergesElement.ValueKind == JsonValueKind.Array)
943foreach (JsonElement merge in mergesElement.EnumerateArray())
955private static IReadOnlyList<PreTokenizer>? GetPreTokenizer(JsonElement root, out bool byteLevel)
960if (root.TryGetProperty("pre_tokenizer", out JsonElement preTokenizerElement) &&
962preTokenizerElement.TryGetProperty("type", out JsonElement typeElement) &&
965preTokenizerElement.TryGetProperty("pretokenizers", out JsonElement preTokenizersElement) &&
968foreach (JsonElement preTokenizer in preTokenizersElement.EnumerateArray())
971preTokenizer.TryGetProperty("type", out JsonElement preTokenizerTypeElement) &&
977if (preTokenizer.TryGetProperty("pattern", out JsonElement patternElement) &&
979patternElement.TryGetProperty("Regex", out JsonElement regexElement) &&
1000private static Dictionary<string, int>? GetSpecialTokens(JsonElement root)
1002if (root.TryGetProperty("added_tokens", out JsonElement modelElement) && modelElement.ValueKind == JsonValueKind.Array)
1005foreach (JsonElement token in modelElement.EnumerateArray())
1007if (token.TryGetProperty("content", out JsonElement contentElement) &&
1009token.TryGetProperty("id", out JsonElement idElement) && idElement.ValueKind == JsonValueKind.Number)
Negotiate.Client (2)
OpenIdConnectSample (2)
Shared (1)
Shared.Tests (4)
SocialSample (2)
System.Text.Json (197)
System\Text\Json\Document\JsonElement.cs (27)
62public JsonElement this[int index]
107/// Gets a <see cref="JsonElement"/> representing the value of a required property identified
118/// A <see cref="JsonElement"/> representing the value of the requested property.
133public JsonElement GetProperty(string propertyName)
137if (TryGetProperty(propertyName, out JsonElement property))
146/// Gets a <see cref="JsonElement"/> representing the value of a required property identified
161/// A <see cref="JsonElement"/> representing the value of the requested property.
173public JsonElement GetProperty(ReadOnlySpan<char> propertyName)
175if (TryGetProperty(propertyName, out JsonElement property))
184/// Gets a <see cref="JsonElement"/> representing the value of a required property identified
201/// A <see cref="JsonElement"/> representing the value of the requested property.
213public JsonElement GetProperty(ReadOnlySpan<byte> utf8PropertyName)
215if (TryGetProperty(utf8PropertyName, out JsonElement property))
253public bool TryGetProperty(string propertyName, out JsonElement value)
287public bool TryGetProperty(ReadOnlySpan<char> propertyName, out JsonElement value)
323public bool TryGetProperty(ReadOnlySpan<byte> utf8PropertyName, out JsonElement value)
1237/// Compares the values of two <see cref="JsonElement"/> values for equality, including the values of all descendant elements.
1239/// <param name="element1">The first <see cref="JsonElement"/> to compare.</param>
1240/// <param name="element2">The second <see cref="JsonElement"/> to compare.</param>
1257public static bool DeepEquals(JsonElement element1, JsonElement element2)
1303foreach (JsonElement e1 in element1.EnumerateArray())
1367Dictionary<string, ValueQueue<JsonElement>> properties2 = new(capacity: remainingProps, StringComparer.Ordinal);
1372ref ValueQueue<JsonElement> values = ref CollectionsMarshal.GetValueRefOrAddDefault(properties2, prop2.Name, out bool _);
1387ref ValueQueue<JsonElement> values = ref CollectionsMarshal.GetValueRefOrAddDefault(properties2, prop.Name, out bool exists);
1391if (!exists || !values.TryDequeue(out JsonElement value) || !DeepEquals(prop.Value, value))
1692public JsonElement Clone()
System\Text\Json\Serialization\JsonSerializer.Write.Element.cs (19)
14/// Converts the provided value into a <see cref="JsonElement"/>.
17/// <returns>A <see cref="JsonElement"/> representation of the JSON value.</returns>
26public static JsonElement SerializeToElement<TValue>(TValue value, JsonSerializerOptions? options = null)
33/// Converts the provided value into a <see cref="JsonElement"/>.
35/// <returns>A <see cref="JsonElement"/> representation of the value.</returns>
51public static JsonElement SerializeToElement(object? value, Type inputType, JsonSerializerOptions? options = null)
59/// Converts the provided value into a <see cref="JsonElement"/>.
62/// <returns>A <see cref="JsonElement"/> representation of the value.</returns>
68public static JsonElement SerializeToElement<TValue>(TValue value, JsonTypeInfo<TValue> jsonTypeInfo)
77/// Converts the provided value into a <see cref="JsonElement"/>.
79/// <returns>A <see cref="JsonElement"/> representation of the value.</returns>
88public static JsonElement SerializeToElement(object? value, JsonTypeInfo jsonTypeInfo)
97/// Converts the provided value into a <see cref="JsonElement"/>.
99/// <returns>A <see cref="JsonElement"/> representation of the value.</returns>
114public static JsonElement SerializeToElement(object? value, Type inputType, JsonSerializerContext context)
123private static JsonElement WriteElement<TValue>(in TValue value, JsonTypeInfo<TValue> jsonTypeInfo)
133return JsonElement.Parse(output.WrittenSpan, options.GetDocumentOptions());
141private static JsonElement WriteElementAsObject(object? value, JsonTypeInfo jsonTypeInfo)
151return JsonElement.Parse(output.WrittenSpan, options.GetDocumentOptions());
Templates.Blazor.Tests (2)
Templates.Blazor.WebAssembly.Auth.Tests (2)
Templates.Blazor.WebAssembly.Tests (2)
Templates.Mvc.Tests (2)
Templates.Tests (2)