9 instantiations of JsonElement
Microsoft.Build (1)
Construction\Solution\SolutionFile.cs (1)
686solution = new JsonElement();
System.Text.Json (8)
System\Text\Json\Document\JsonDocument.cs (4)
35public JsonElement RootElement => new JsonElement(this, 0); 171return new JsonElement(this, currentIndex + ((arrayIndex + 1) * DbRow.Size)); 181return new JsonElement(this, objectOffset); 1056JsonElement curr = new JsonElement(document, traversalPath.Peek());
System\Text\Json\Document\JsonDocument.TryGetProperty.cs (2)
198value = new JsonElement(this, index + DbRow.Size); 216value = new JsonElement(this, index + DbRow.Size);
System\Text\Json\Document\JsonElement.ArrayEnumerator.cs (1)
42return new JsonElement(_target._parent, _curIdx);
System\Text\Json\Document\JsonElement.ObjectEnumerator.cs (1)
41return new JsonProperty(new JsonElement(_target._parent, _curIdx));
1146 references to JsonElement
aspire (97)
Backchannel\AppHostAuxiliaryBackchannel.cs (4)
386IReadOnlyDictionary<string, JsonElement>? arguments, 644Dictionary<string, JsonElement>? arguments = null; 645if (request.Arguments is JsonElement argsElement && argsElement.ValueKind == JsonValueKind.Object) 647arguments = new Dictionary<string, JsonElement>();
Backchannel\BackchannelJsonSerializerContext.cs (2)
24[JsonSerializable(typeof(JsonElement))] 55[JsonSerializable(typeof(Dictionary<string, JsonElement>))]
Backchannel\IAppHostAuxiliaryBackchannel.cs (1)
100IReadOnlyDictionary<string, JsonElement>? arguments,
Commands\AgentMcpCommand.cs (2)
185? new Dictionary<string, JsonElement>(a) 223? new Dictionary<string, JsonElement>(a)
Commands\InitCommand.cs (5)
657var rootElement = jsonDoc.RootElement; 658if (rootElement.TryGetProperty("Properties", out var properties)) 661if (properties.TryGetProperty("IsAspireHost", out var isAspireHostElement)) 672if (properties.TryGetProperty("OutputType", out var outputTypeElement)) 679if (properties.TryGetProperty("TargetFramework", out var targetFrameworkElement))
Commands\McpCallCommand.cs (2)
87IReadOnlyDictionary<string, JsonElement>? arguments = null; 98var dict = new Dictionary<string, JsonElement>();
Configuration\AspireConfigFile.cs (3)
213if (!doc.RootElement.TryGetProperty("profiles", out var profilesElement)) 223if (prop.Value.TryGetProperty("applicationUrl", out var appUrl) && 229if (prop.Value.TryGetProperty("environmentVariables", out var envVars) &&
Configuration\AspireJsonConfiguration.cs (1)
82public Dictionary<string, JsonElement>? ExtensionData { get; set; }
DotNet\DotNetCliRunner.cs (13)
245var rootElement = jsonDocument.RootElement; 247if (!rootElement.TryGetProperty("Properties", out var properties)) 252if (!properties.TryGetProperty("IsAspireHost", out var isAspireHostElement)) 262if (rootElement.TryGetProperty("Items", out var items)) 265if (items.TryGetProperty("PackageReference", out var packageReferences)) 267foreach (var packageRef in packageReferences.EnumerateArray()) 269if (packageRef.TryGetProperty("Identity", out var identity) && 271packageRef.TryGetProperty("Version", out var version)) 280if (aspireHostingVersion == null && items.TryGetProperty("AspireProjectOrPackageReference", out var aspireProjectOrPackageReferences)) 282foreach (var aspireRef in aspireProjectOrPackageReferences.EnumerateArray()) 284if (aspireRef.TryGetProperty("Identity", out var identity) && 286aspireRef.TryGetProperty("Version", out var version)) 296if (aspireHostingVersion == null && properties.TryGetProperty("AspireHostingSDKVersion", out var aspireHostingSdkVersionElement))
Mcp\Tools\CallToolContext.cs (1)
27public required IReadOnlyDictionary<string, JsonElement>? Arguments { get; init; }
Mcp\Tools\CliMcpTool.cs (1)
28public abstract JsonElement GetInputSchema();
Mcp\Tools\DoctorTool.cs (1)
19public override JsonElement GetInputSchema()
Mcp\Tools\ExecuteResourceCommandTool.cs (3)
24public override JsonElement GetInputSchema() 48!arguments.TryGetValue("resourceName", out var resourceNameElement) || 49!arguments.TryGetValue("commandName", out var commandNameElement))
Mcp\Tools\GetDocTool.cs (3)
25public override JsonElement GetInputSchema() 51if (arguments is null || !arguments.TryGetValue("slug", out var slugElement)) 71if (arguments.TryGetValue("section", out var sectionElement))
Mcp\Tools\ListAppHostsTool.cs (1)
33public override JsonElement GetInputSchema()
Mcp\Tools\ListConsoleLogsTool.cs (2)
23public override JsonElement GetInputSchema() 45if (arguments is not null && arguments.TryGetValue("resourceName", out var resourceNameElement))
Mcp\Tools\ListDocsTool.cs (1)
28public override JsonElement GetInputSchema()
Mcp\Tools\ListIntegrationsTool.cs (1)
58public override JsonElement GetInputSchema()
Mcp\Tools\ListResourcesTool.cs (1)
52public override JsonElement GetInputSchema()
Mcp\Tools\ListStructuredLogsTool.cs (2)
28public override JsonElement GetInputSchema() 50if (arguments?.TryGetValue("resourceName", out var resourceNameElement) == true &&
Mcp\Tools\ListTracesTool.cs (2)
28public override JsonElement GetInputSchema() 50if (arguments?.TryGetValue("resourceName", out var resourceNameElement) == true &&
Mcp\Tools\ListTraceStructuredLogsTool.cs (2)
28public override JsonElement GetInputSchema() 51if (arguments?.TryGetValue("traceId", out var traceIdElement) == true &&
Mcp\Tools\RefreshToolsTool.cs (1)
15public override JsonElement GetInputSchema()
Mcp\Tools\SearchDocsTool.cs (3)
27public override JsonElement GetInputSchema() 54if (arguments is null || !arguments.TryGetValue("query", out var queryElement)) 74if (arguments.TryGetValue("topK", out var topKElement) && topKElement.TryGetInt32(out var topKValue))
Mcp\Tools\SelectAppHostTool.cs (2)
19public override JsonElement GetInputSchema() 39if (arguments == null || !arguments.TryGetValue("appHostPath", out var appHostPathElement))
Npm\SigstoreNpmProvenanceChecker.cs (10)
268if (predicate.TryGetProperty("buildDefinition", out var buildDefinition) && 271if (buildDefinition.TryGetProperty("buildType", out var buildTypeElement) && 277if (buildDefinition.TryGetProperty("externalParameters", out var extParams) && 279extParams.TryGetProperty("workflow", out var workflow) && 282if (workflow.TryGetProperty("repository", out var repoEl) && 288if (workflow.TryGetProperty("path", out var pathEl) && 294if (workflow.TryGetProperty("ref", out var refEl) && 302if (predicate.TryGetProperty("runDetails", out var runDetails) && 304runDetails.TryGetProperty("builder", out var builder) && 307if (builder.TryGetProperty("id", out var idEl) &&
Projects\DotNetAppHostProject.cs (3)
566var rootElement = jsonDocument.RootElement; 567if (rootElement.TryGetProperty("Properties", out var properties) && 568properties.TryGetProperty("UserSecretsId", out var userSecretsIdElement))
Projects\GuestAppHostProject.cs (5)
642if (!doc.RootElement.TryGetProperty("profiles", out var profiles)) 648JsonElement? profileElement = null; 649if (profiles.TryGetProperty("https", out var httpsProfile)) 671if (profileElement.Value.TryGetProperty("applicationUrl", out var appUrl) && 678if (profileElement.Value.TryGetProperty("environmentVariables", out var envVars))
Projects\ProjectLocator.cs (1)
221if (json.RootElement.TryGetProperty("appHostPath", out var appHostPathProperty) && appHostPathProperty.GetString() is { } appHostPath)
Projects\ProjectUpdater.cs (12)
262var propertiesElement = itemsAndPropertiesDocument.RootElement.GetProperty("Properties"); 263var sdkVersionElement = propertiesElement.GetProperty("AspireHostingSDKVersion"); 612if (itemsAndPropertiesDocument.RootElement.TryGetProperty("Properties", out var propertiesElement)) 614if (propertiesElement.TryGetProperty("ManagePackageVersionsCentrally", out var managePkgVersionsElement)) 630var itemsElement = itemsAndPropertiesDocument.RootElement.GetProperty("Items"); 633if (itemsElement.TryGetProperty("ProjectReference", out var projectReferencesElement)) 635foreach (var projectReference in projectReferencesElement.EnumerateArray()) 644if (itemsElement.TryGetProperty("PackageReference", out var packageReferencesElement)) 646foreach (var packageReference in packageReferencesElement.EnumerateArray()) 662if (!packageReference.TryGetProperty("Version", out var versionElement)) 841var propertiesElement = document.RootElement.GetProperty("Properties"); 842if (propertiesElement.TryGetProperty(propertyName, out var propertyElement))
src\Aspire.Hosting\Backchannel\BackchannelDataTypes.cs (1)
212public JsonElement? Arguments { get; init; }
src\Shared\PackageUpdateHelpers.cs (5)
133if (!document.RootElement.TryGetProperty("searchResult", out var searchResultsArray)) 138foreach (var sourceResult in searchResultsArray.EnumerateArray()) 141var sourcePackagesArray = sourceResult.GetProperty("packages"); 143foreach (var packageResult in sourcePackagesArray.EnumerateArray()) 147var version = packageResult.TryGetProperty("latestVersion", out var latestVersionProp)
Aspire.Azure.Npgsql (6)
src\Components\Common\ManagedIdentityTokenCredentialHelpers.cs (6)
91var payloadJson = JsonElement.ParseValue(ref reader); 94if (payloadJson.TryGetProperty("xms_mirid", out var xms_mirid) && 100else if (payloadJson.TryGetProperty("upn", out var upn)) 104else if (payloadJson.TryGetProperty("preferred_username", out var preferredUsername)) 108else if (payloadJson.TryGetProperty("unique_name", out var uniqueName))
Aspire.Azure.Npgsql.EntityFrameworkCore.PostgreSQL (6)
src\Components\Common\ManagedIdentityTokenCredentialHelpers.cs (6)
91var payloadJson = JsonElement.ParseValue(ref reader); 94if (payloadJson.TryGetProperty("xms_mirid", out var xms_mirid) && 100else if (payloadJson.TryGetProperty("upn", out var upn)) 104else if (payloadJson.TryGetProperty("preferred_username", out var preferredUsername)) 108else if (payloadJson.TryGetProperty("unique_name", out var uniqueName))
Aspire.Cli.Tests (32)
Backchannel\BackchannelJsonSerializerContextTests.cs (2)
49var payload = new Dictionary<string, JsonElement>(StringComparer.Ordinal) 56var roundTripped = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(json, options);
Commands\PsCommandTests.cs (1)
323var firstElement = document.RootElement[0];
Mcp\ExecuteResourceCommandToolTests.cs (1)
15private static IReadOnlyDictionary<string, JsonElement> CreateArguments(string resourceName, string commandName)
Mcp\ListConsoleLogsToolTests.cs (6)
22var arguments = new Dictionary<string, JsonElement> 61var arguments = new Dictionary<string, JsonElement> 96var arguments = new Dictionary<string, JsonElement> 130var arguments = new Dictionary<string, JsonElement> 160var arguments = new Dictionary<string, JsonElement> 189var arguments = new Dictionary<string, JsonElement>
Mcp\ListIntegrationsToolTests.cs (9)
34var schema = tool.GetInputSchema(); 37Assert.True(schema.TryGetProperty("type", out var typeElement)); 39Assert.True(schema.TryGetProperty("properties", out var propsElement)); 41Assert.True(schema.TryGetProperty("description", out var descElement)); 43Assert.True(schema.TryGetProperty("additionalProperties", out var additionalPropsElement)); 63Assert.True(json.RootElement.TryGetProperty("integrations", out var integrations)); 88Assert.True(json.RootElement.TryGetProperty("integrations", out var integrations)); 93var firstIntegration = integrations[0]; 122Assert.True(json.RootElement.TryGetProperty("integrations", out var integrations));
Mcp\ListResourcesToolTests.cs (1)
179var resource = jsonDoc.RootElement[0];
Mcp\ListStructuredLogsToolTests.cs (7)
333var arguments = new Dictionary<string, JsonElement> 369var schema = tool.GetInputSchema(); 372Assert.True(schema.TryGetProperty("properties", out var properties)); 373Assert.True(properties.TryGetProperty("resourceName", out var resourceName)); 374Assert.True(resourceName.TryGetProperty("type", out var type)); 383var schema = tool.GetInputSchema(); 386if (schema.TryGetProperty("required", out var required))
Mcp\ListTracesToolTests.cs (2)
315var arguments = new Dictionary<string, JsonElement> 418var arguments = new Dictionary<string, JsonElement>
TestServices\CallToolContextTestHelper.cs (1)
22IReadOnlyDictionary<string, JsonElement>? arguments = null,
TestServices\TestAppHostAuxiliaryBackchannel.cs (2)
47public Func<string, string, IReadOnlyDictionary<string, JsonElement>?, CancellationToken, Task<CallToolResult>>? CallResourceMcpToolHandler { get; set; } 131IReadOnlyDictionary<string, JsonElement>? arguments,
Aspire.Dashboard (3)
Model\GenAI\GenAIItemPartViewModel.cs (1)
138private static JsonObject ToJsonObject(Dictionary<string, JsonElement> dict)
Model\GenAI\GenAIMessages.cs (2)
167public Dictionary<string, JsonElement>? AdditionalProperties { get; set; } 215if (!doc.RootElement.TryGetProperty("type", out var typeProp))
Aspire.Dashboard.Tests (7)
DashboardOptionsTests.cs (5)
318var jsonElement = JsonDocument.Parse(""" 346var jsonElement = JsonDocument.Parse(""" 375var jsonElement = JsonDocument.Parse(""" 411var jsonElement = JsonDocument.Parse(""" 450var jsonElement = JsonDocument.Parse("""
Model\GenAIItemPartViewModelTests.cs (2)
157AdditionalProperties = new Dictionary<string, JsonElement> 178AdditionalProperties = new Dictionary<string, JsonElement>
Aspire.Hosting (15)
Backchannel\AuxiliaryBackchannelRpcTarget.cs (3)
175if (request.Arguments is JsonElement argsElement && argsElement.ValueKind == JsonValueKind.Object) 927private static object? ConvertJsonElementToObject(JsonElement element) 942private static object ConvertJsonNumber(JsonElement element)
Backchannel\BackchannelDataTypes.cs (1)
212public JsonElement? Arguments { get; init; }
Dcp\DcpLogParser.cs (6)
143var root = doc.RootElement; 158("Cmd", root.TryGetProperty("Cmd", out var cmdProp) ? cmdProp.GetString() : null), 159("Args", root.TryGetProperty("Args", out var argsProp) ? argsProp.ToString() : null), 160("ContainerName", root.TryGetProperty("ContainerName", out var containerNameProp) ? containerNameProp.GetString() : null), 161("ContainerId", root.TryGetProperty("ContainerID", out var containerIdProp) ? containerIdProp.GetString() : null), 162("Error", root.TryGetProperty("error", out var errorProp) ? errorProp.GetString() : null)
src\Shared\PackageUpdateHelpers.cs (5)
133if (!document.RootElement.TryGetProperty("searchResult", out var searchResultsArray)) 138foreach (var sourceResult in searchResultsArray.EnumerateArray()) 141var sourcePackagesArray = sourceResult.GetProperty("packages"); 143foreach (var packageResult in sourcePackagesArray.EnumerateArray()) 147var version = packageResult.TryGetProperty("latestVersion", out var latestVersionProp)
Aspire.Hosting.JavaScript (2)
JavaScriptHostingExtensions.cs (2)
1223if (packageJson.RootElement.TryGetProperty("engines", out var engines) && 1224engines.TryGetProperty("node", out var nodeVersion))
Aspire.Hosting.Maui (3)
Utilities\ProjectFileReader.cs (3)
86var properties = jsonDoc.RootElement.GetProperty("Properties"); 91if (properties.TryGetProperty("TargetFrameworks", out var targetFrameworks)) 97properties.TryGetProperty("TargetFramework", out var targetFramework))
Aspire.Hosting.OpenAI (3)
OpenAIHealthCheck.cs (3)
98if (!doc.RootElement.TryGetProperty("status", out var statusEl)) 103var indicator = statusEl.TryGetProperty("indicator", out var indEl) && indEl.ValueKind == JsonValueKind.String 107var description = statusEl.TryGetProperty("description", out var descEl) && descEl.ValueKind == JsonValueKind.String
Aspire.Hosting.PostgreSQL.Tests (1)
AddPostgresTests.cs (1)
510var servers = document.RootElement.GetProperty("Servers");
Aspire.Hosting.Seq.Tests (2)
SeqFunctionalTests.cs (2)
63var doc = jsonDocument.RootElement.EnumerateArray().FirstOrDefault(); 66var property = doc.GetProperty("Properties").EnumerateArray().FirstOrDefault();
Aspire.Hosting.Tests (39)
Backchannel\AuxiliaryBackchannelTests.cs (2)
332await rpc.InvokeAsync<JsonElement>( 373await rpc.InvokeAsync<JsonElement>(
Backchannel\JsonElementConversionTests.cs (1)
19private static object? ConvertJsonElementToObject(JsonElement element)
Dashboard\DashboardLifecycleHookTests.cs (4)
340var customConfig = JsonSerializer.Deserialize<JsonElement>(customConfigContent); 343var netCoreFramework = frameworks.First(f => f.GetProperty("name").GetString() == "Microsoft.NETCore.App"); 344var aspNetCoreFramework = frameworks.First(f => f.GetProperty("name").GetString() == "Microsoft.AspNetCore.App");
ManifestGenerationTests.cs (32)
32var resources = manifestStore.ManifestDocument.RootElement.GetProperty("resources"); 33var x = resources.GetProperty("x"); 34var inputs = x.GetProperty("inputs"); 35var value = inputs.GetProperty("value"); 50var resources = manifestStore.ManifestDocument.RootElement.GetProperty("resources"); 51var x = resources.GetProperty("x"); 52var inputs = x.GetProperty("inputs"); 53var value = inputs.GetProperty("value"); 68var resources = manifestStore.ManifestDocument.RootElement.GetProperty("resources"); 69var x = resources.GetProperty("x"); 70var inputs = x.GetProperty("inputs"); 71var value = inputs.GetProperty("value"); 72Assert.True(value.TryGetProperty("secret", out var secret)); 86var resources = manifestStore.ManifestDocument.RootElement.GetProperty("resources"); 88var workerA = resources.GetProperty("workera"); 129var resources = manifestStore.ManifestDocument.RootElement.GetProperty("resources"); 156var resources = manifestStore.ManifestDocument.RootElement.GetProperty("resources"); 158var resource = resources.GetProperty("program"); 159var args = resource.GetProperty("args"); 162var verify = new List<Action<JsonElement>>(); 189var resources = manifestStore.ManifestDocument.RootElement.GetProperty("resources"); 191var resource = resources.GetProperty("program"); 209var resources = manifestStore.ManifestDocument.RootElement.GetProperty("resources"); 211var container = resources.GetProperty("rediscontainer"); 229var resources = manifestStore.ManifestDocument.RootElement.GetProperty("resources"); 231var container = resources.GetProperty("rediscontainer"); 251var resources = manifestStore.ManifestDocument.RootElement.GetProperty("resources"); 253var server = resources.GetProperty("postgrescontainer"); 256var db = resources.GetProperty("postgresdatabase"); 274var resources = manifestStore.ManifestDocument.RootElement.GetProperty("resources"); 276var container = resources.GetProperty("testresource"); 277Assert.False(container.TryGetProperty("metadata", out var _));
Aspire.Templates.Tests (2)
LocalhostTldHostnameTests.cs (2)
69var profiles = launchSettings.RootElement.GetProperty("profiles"); 74if (profile.Value.TryGetProperty("applicationUrl", out var applicationUrl))
dotnet (17)
Commands\Run\CSharpCompilerCommand.cs (3)
360JsonElement root = jsonDoc.RootElement; 361if (!root.TryGetProperty("runtimeOptions", out JsonElement runtimeOptions) || 362!runtimeOptions.TryGetProperty("framework", out JsonElement framework)) return null;
RuntimeConfig.cs (3)
26JsonElement root = doc.RootElement; 27if (root.TryGetProperty("runtimeOptions", out var runtimeOptionsRoot)) 29if (runtimeOptionsRoot.TryGetProperty("framework", out var framework))
SlnFileFactory.cs (1)
97JsonElement root = JsonDocument.Parse(File.ReadAllText(filteredSolutionPath), options).RootElement;
ToolManifest\JsonElementExtension.cs (6)
14internal static bool TryGetStringValue(this JsonElement element, string name, out string value) 17if (element.TryGetProperty(name, out JsonElement jsonValue)) 34internal static bool TryGetInt32Value(this JsonElement element, string name, out int value) 37if (element.TryGetProperty(name, out JsonElement jsonValue)) 54internal static bool TryGetBooleanValue(this JsonElement element, string name, out bool value) 57if (element.TryGetProperty(name, out JsonElement jsonValue))
ToolManifest\ToolManifestEditor.cs (4)
141JsonElement root = doc.RootElement; 153if (root.TryGetProperty(JsonPropertyTools, out var tools)) 177if (toolJson.Value.TryGetProperty(JsonPropertyCommands, out var commandsJson)) 187foreach (var command in commandsJson.EnumerateArray())
dotnet-sourcelink (1)
dotnet-user-jwts (8)
Helpers\DevJwtCliHelpers.cs (8)
170if (launchSettingsJson.RootElement.TryGetProperty("profiles", out var profiles)) 185static List<string> ExtractIISExpressUrlFromProfile(JsonElement rootElement) 187if (rootElement.TryGetProperty("iisSettings", out var iisSettings)) 189if (iisSettings.TryGetProperty("iisExpress", out var iisExpress)) 192if (iisExpress.TryGetProperty("applicationUrl", out var iisUrl)) 197if (iisExpress.TryGetProperty("sslPort", out var sslPort)) 211if (profile.Value.TryGetProperty("commandName", out var commandName)) 215if (profile.Value.TryGetProperty("applicationUrl", out var applicationUrl))
ILCompiler.Compiler (1)
src\runtime\src\coreclr\tools\Common\Microsoft\SourceLink\Tools\SourceLinkMap.cs (1)
65var root = jsonDocument.RootElement;
ILCompiler.ReadyToRun (4)
Compiler\CallChainProfile.cs (4)
252JsonElement root = document.RootElement; 259foreach (JsonElement methodListArray in methodAndCallees.Value.EnumerateArray()) 264foreach (JsonElement followingMethods in methodListArray.EnumerateArray()) 275foreach (JsonElement methodCount in methodListArray.EnumerateArray())
Infrastructure.Tests (11)
PowerShellScripts\ExpandTestMatrixGitHubTests.cs (7)
152Assert.True(document.RootElement.TryGetProperty("include", out var include)); 179var include = document.RootElement.GetProperty("include"); 181var firstEntry = include.ValueKind == JsonValueKind.Array 210var include = document.RootElement.GetProperty("include"); 212var firstEntry = include.ValueKind == JsonValueKind.Array 216Assert.True(firstEntry.TryGetProperty("runs-on", out var runsOn), 666var include = document.RootElement.GetProperty("include");
PowerShellScripts\SplitTestMatrixByDepsTests.cs (1)
325var include = document.RootElement.GetProperty("include");
PowerShellScripts\SplitTestProjectsTests.cs (1)
121Assert.True(document.RootElement.TryGetProperty("testPartitions", out var partitions));
WorkflowScripts\AutoRerunTransientCiFailuresTests.cs (2)
1209public JsonElement[][] Rows { get; init; } = []; 1236public JsonElement Payload { get; init; }
Microsoft.AspNetCore.Authentication (4)
JsonDocumentAuthExtensions.cs (4)
14/// Gets a string property value from the specified <see cref="JsonElement"/>. 16/// <param name="element">The <see cref="JsonElement"/>.</param> 19public static string? GetString(this JsonElement element, string key) 21if (element.TryGetProperty(key, out var property) && property.ValueKind != JsonValueKind.Null)
Microsoft.AspNetCore.Authentication.OAuth (24)
ClaimAction.cs (1)
42public abstract void Run(JsonElement userData, ClaimsIdentity identity, string issuer);
ClaimActionCollectionMapExtensions.cs (2)
82public static void MapCustomJson(this ClaimActionCollection collection, string claimType, Func<JsonElement, string?> resolver) 97public static void MapCustomJson(this ClaimActionCollection collection, string claimType, string valueType, Func<JsonElement, string?> resolver)
CustomJsonClaimAction.cs (3)
20public CustomJsonClaimAction(string claimType, string valueType, Func<JsonElement, string?> resolver) 29public Func<JsonElement, string?> Resolver { get; } 32public override void Run(JsonElement userData, ClaimsIdentity identity, string issuer)
DeleteClaimAction.cs (1)
25public override void Run(JsonElement userData, ClaimsIdentity identity, string issuer)
Events\OAuthCreatingTicketContext.cs (4)
36JsonElement user) 51/// <see cref="JsonElement"/> if it is not available. 53public JsonElement User { get; } 113public void RunClaimActions(JsonElement userData)
JsonKeyClaimAction.cs (3)
33public override void Run(JsonElement userData, ClaimsIdentity identity, string issuer) 35if (!userData.TryGetProperty(JsonKey, out var value)) 41foreach (var v in value.EnumerateArray())
JsonSubKeyClaimAction.cs (5)
35public override void Run(JsonElement userData, ClaimsIdentity identity, string issuer) 37if (!TryGetSubProperty(userData, JsonKey, SubKey, out var value)) 43foreach (var v in value.EnumerateArray()) 55private static bool TryGetSubProperty(JsonElement userData, string propertyName, string subProperty, out JsonElement value)
MapAllClaimsAction.cs (1)
23public override void Run(JsonElement userData, ClaimsIdentity identity, string issuer)
OAuthTokenResponse.cs (4)
21var root = response.RootElement; 95var root = response.RootElement; 106if (root.TryGetProperty("error_description", out var errorDescription)) 112if (root.TryGetProperty("error_uri", out var errorUri))
Microsoft.AspNetCore.Components.Endpoints (19)
src\aspnetcore\src\Components\Shared\src\RenderFragmentSerializer.cs (6)
239builder.SetKey(node.Key is JsonElement je ? ConvertTypedValue(je, node.KeyTypeAssembly!, node.KeyTypeName!, jsonOptions, typeCache) : node.Key); 266builder.SetKey(node.Key is JsonElement je ? ConvertTypedValue(je, node.KeyTypeAssembly!, node.KeyTypeName!, jsonOptions, typeCache) : node.Key); 287var value = attr.Value is JsonElement je 315JsonElement je => JsonSerializer.Deserialize<SerializedRenderFragment>(je.GetRawText(), jsonOptions), 322return attr.Value is JsonElement json ? ConvertTypedValue(json, attr.TypeAssembly!, attr.TypeName!, jsonOptions, typeCache) : attr.Value; 326private static object? ConvertTypedValue(JsonElement json, string assemblyName, string typeName, JsonSerializerOptions? jsonOptions, ComponentParametersTypeCache typeCache)
TempData\CookieTempDataProvider.cs (3)
69Dictionary<string, JsonElement>? dataFromCookie; 75dataFromCookie = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(unprotectBuffer.WrittenSpan); 80dataFromCookie = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(unprotectedBytes);
TempData\ITempDataSerializer.cs (1)
10public IDictionary<string, object?> DeserializeData(IDictionary<string, JsonElement> data);
TempData\JsonTempDataSerializer.cs (8)
12public IDictionary<string, object?> DeserializeData(IDictionary<string, JsonElement> data) 22private static object? DeserializeElement(JsonElement element) 37private static object? DeserializeString(JsonElement element) 48private static object? DeserializeArray(JsonElement element) 58foreach (var item in element.EnumerateArray()) 65private static Dictionary<string, object?> DeserializeObject(JsonElement element) 75private static Type GetArrayTypeInfo(JsonElement element) 87private static Type GetStringType(JsonElement element)
TempData\SessionStorageTempDataProvider.cs (1)
34var dataFromSession = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(value);
Microsoft.AspNetCore.Components.Server (14)
BlazorPack\BlazorPackHubProtocolWorker.cs (2)
51else if (type == typeof(JsonElement)) 60return JsonElement.ParseValue(ref jsonReader);
Circuits\ComponentParameterDeserializer.cs (4)
57var value = (JsonElement)parameterValues[i]; 81var value = (JsonElement)parameterValues[i];
src\aspnetcore\src\Components\Shared\src\RenderFragmentSerializer.cs (6)
239builder.SetKey(node.Key is JsonElement je ? ConvertTypedValue(je, node.KeyTypeAssembly!, node.KeyTypeName!, jsonOptions, typeCache) : node.Key); 266builder.SetKey(node.Key is JsonElement je ? ConvertTypedValue(je, node.KeyTypeAssembly!, node.KeyTypeName!, jsonOptions, typeCache) : node.Key); 287var value = attr.Value is JsonElement je 315JsonElement je => JsonSerializer.Deserialize<SerializedRenderFragment>(je.GetRawText(), jsonOptions), 322return attr.Value is JsonElement json ? ConvertTypedValue(json, attr.TypeAssembly!, attr.TypeName!, jsonOptions, typeCache) : attr.Value; 326private static object? ConvertTypedValue(JsonElement json, string assemblyName, string typeName, JsonSerializerOptions? jsonOptions, ComponentParametersTypeCache typeCache)
src\aspnetcore\src\Components\Shared\src\WebRootComponentParameters.cs (2)
51if (value is JsonElement jsonValue && otherValue is JsonElement otherJsonValue)
Microsoft.AspNetCore.Components.Web (36)
JSComponents\JSComponentInterop.cs (2)
81protected internal void SetRootComponentParameters(int componentId, int parameterCount, JsonElement parametersJson, JsonSerializerOptions jsonOptions) 97var parameterJsonValue = jsonProperty.Value;
WebEventData\ChangeEventArgsReader.cs (5)
14internal static ChangeEventArgs Read(JsonElement jsonElement) 21var value = property.Value; 50private static string?[] GetJsonElementStringArrayValue(JsonElement jsonElement) 55foreach (var arrayElement in jsonElement.EnumerateArray()) 60$"Unsupported {nameof(JsonElement)} value kind '{arrayElement.ValueKind}' " +
WebEventData\ClipboardEventArgsReader.cs (1)
14internal static ClipboardEventArgs Read(JsonElement jsonElement)
WebEventData\DragEventArgsReader.cs (7)
21internal static DragEventArgs Read(JsonElement jsonElement) 39private static DataTransfer ReadDataTransfer(JsonElement jsonElement) 58var value = property.Value; 61foreach (var item in value.EnumerateArray()) 80private static DataTransferItem ReadDataTransferItem(JsonElement jsonElement) 102private static string[] ReadStringArray(JsonElement value) 106foreach (var item in value.EnumerateArray())
WebEventData\ErrorEventArgsReader.cs (1)
18internal static ErrorEventArgs Read(JsonElement jsonElement)
WebEventData\FocusEventArgsReader.cs (1)
14internal static FocusEventArgs Read(JsonElement jsonElement)
WebEventData\KeyboardEventArgsReader.cs (1)
23internal static KeyboardEventArgs Read(JsonElement jsonElement)
WebEventData\MouseEventArgsReader.cs (1)
31internal static MouseEventArgs Read(JsonElement jsonElement)
WebEventData\PointerEventArgsReader.cs (1)
21internal static PointerEventArgs Read(JsonElement jsonElement)
WebEventData\ProgressEventArgReader.cs (1)
17internal static ProgressEventArgs Read(JsonElement jsonElement)
WebEventData\TouchEventArgsReader.cs (4)
29internal static TouchEventArgs Read(JsonElement jsonElement) 79private static TouchPoint[] ReadTouchPointArray(JsonElement jsonElement) 83foreach (var item in jsonElement.EnumerateArray()) 91private static TouchPoint ReadTouchPoint(JsonElement jsonElement)
WebEventData\WebEventData.cs (5)
19JsonElement eventDescriptorJson, 20JsonElement eventArgsJson) 39JsonElement eventArgsJson) 68JsonElement eventArgsJson) 89JsonElement eventArgsJson,
WebEventData\WebEventDescriptorReader.cs (2)
19internal static WebEventDescriptor Read(JsonElement jsonElement) 45private static EventFieldInfo? ReadEventFieldInfo(JsonElement jsonElement)
WebEventData\WheelEventArgsReader.cs (1)
17internal static WheelEventArgs Read(JsonElement jsonElement)
WebRenderer.cs (3)
161public Task DispatchEventAsync(JsonElement eventDescriptor, JsonElement eventArgs) 175public void SetRootComponentParameters(int componentId, int parameterCount, JsonElement parametersJson)
Microsoft.AspNetCore.Http.Extensions (10)
_generated\12\ProblemDetailsJsonContext.GetJsonTypeInfo.g.cs (1)
38if (type == typeof(global::System.Text.Json.JsonElement))
_generated\5\ProblemDetailsJsonContext.JsonElement.g.cs (8)
13private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.JsonElement>? _JsonElement; 19public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.JsonElement> JsonElement 22get => _JsonElement ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.JsonElement>)Options.GetTypeInfo(typeof(global::System.Text.Json.JsonElement)); 25private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.JsonElement> Create_JsonElement(global::System.Text.Json.JsonSerializerOptions options) 27if (!TryGetTypeInfoForRuntimeCustomConverter<global::System.Text.Json.JsonElement>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.JsonElement> jsonTypeInfo)) 29jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo<global::System.Text.Json.JsonElement>(options, global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.JsonElementConverter);
ProblemDetailsJsonContext.cs (1)
14[JsonSerializable(typeof(JsonElement))]
Microsoft.AspNetCore.Identity (44)
_generated\31\IdentityJsonSerializerContext.PublicKeyCredentialAuthenticatorAssertionResponse.g.cs (6)
32ObjectWithParameterizedConstructorCreator = static args => new global::Microsoft.AspNetCore.Identity.PublicKeyCredential<global::Microsoft.AspNetCore.Identity.AuthenticatorAssertionResponse>(){ Id = (global::Microsoft.AspNetCore.Identity.BufferSource)args[0], Type = (string)args[1], ClientExtensionResults = (global::System.Text.Json.JsonElement)args[2], Response = (global::Microsoft.AspNetCore.Identity.AuthenticatorAssertionResponse)args[3] }, 99var info2 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::System.Text.Json.JsonElement> 114AttributeProviderFactory = static () => typeof(global::Microsoft.AspNetCore.Identity.PublicKeyCredential<global::Microsoft.AspNetCore.Identity.AuthenticatorAssertionResponse>).GetProperty("ClientExtensionResults", InstanceMemberBindingFlags, null, typeof(global::System.Text.Json.JsonElement), global::System.Array.Empty<global::System.Type>(), null), 117properties[2] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::System.Text.Json.JsonElement>(options, info2); 229ParameterType = typeof(global::System.Text.Json.JsonElement), 253public static extern void __set_PublicKeyCredentialAuthenticatorAssertionResponse_ClientExtensionResults(global::Microsoft.AspNetCore.Identity.PublicKeyCredential<TResponse> obj, global::System.Text.Json.JsonElement value);
_generated\32\IdentityJsonSerializerContext.PublicKeyCredentialAuthenticatorAttestationResponse.g.cs (6)
32ObjectWithParameterizedConstructorCreator = static args => new global::Microsoft.AspNetCore.Identity.PublicKeyCredential<global::Microsoft.AspNetCore.Identity.AuthenticatorAttestationResponse>(){ Id = (global::Microsoft.AspNetCore.Identity.BufferSource)args[0], Type = (string)args[1], ClientExtensionResults = (global::System.Text.Json.JsonElement)args[2], Response = (global::Microsoft.AspNetCore.Identity.AuthenticatorAttestationResponse)args[3] }, 99var info2 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::System.Text.Json.JsonElement> 114AttributeProviderFactory = static () => typeof(global::Microsoft.AspNetCore.Identity.PublicKeyCredential<global::Microsoft.AspNetCore.Identity.AuthenticatorAttestationResponse>).GetProperty("ClientExtensionResults", InstanceMemberBindingFlags, null, typeof(global::System.Text.Json.JsonElement), global::System.Array.Empty<global::System.Type>(), null), 117properties[2] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::System.Text.Json.JsonElement>(options, info2); 229ParameterType = typeof(global::System.Text.Json.JsonElement), 253public static extern void __set_PublicKeyCredentialAuthenticatorAttestationResponse_ClientExtensionResults(global::Microsoft.AspNetCore.Identity.PublicKeyCredential<TResponse> obj, global::System.Text.Json.JsonElement value);
_generated\33\IdentityJsonSerializerContext.PublicKeyCredentialCreationOptions.g.cs (5)
270var info10 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::System.Text.Json.JsonElement?> 285AttributeProviderFactory = static () => typeof(global::Microsoft.AspNetCore.Identity.PublicKeyCredentialCreationOptions).GetProperty("Extensions", InstanceMemberBindingFlags, null, typeof(global::System.Text.Json.JsonElement?), global::System.Array.Empty<global::System.Type>(), null), 288properties[10] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::System.Text.Json.JsonElement?>(options, info10); 364global::System.Text.Json.JsonElement? __value_Extensions = ((global::Microsoft.AspNetCore.Identity.PublicKeyCredentialCreationOptions)value).Extensions; 425private static extern void __set_PublicKeyCredentialCreationOptions_Extensions(global::Microsoft.AspNetCore.Identity.PublicKeyCredentialCreationOptions obj, global::System.Text.Json.JsonElement? value);
_generated\36\IdentityJsonSerializerContext.PublicKeyCredentialRequestOptions.g.cs (5)
180var info6 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::System.Text.Json.JsonElement?> 195AttributeProviderFactory = static () => typeof(global::Microsoft.AspNetCore.Identity.PublicKeyCredentialRequestOptions).GetProperty("Extensions", InstanceMemberBindingFlags, null, typeof(global::System.Text.Json.JsonElement?), global::System.Array.Empty<global::System.Type>(), null), 198properties[6] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::System.Text.Json.JsonElement?>(options, info6); 249global::System.Text.Json.JsonElement? __value_Extensions = ((global::Microsoft.AspNetCore.Identity.PublicKeyCredentialRequestOptions)value).Extensions; 284private static extern void __set_PublicKeyCredentialRequestOptions_Extensions(global::Microsoft.AspNetCore.Identity.PublicKeyCredentialRequestOptions obj, global::System.Text.Json.JsonElement? value);
_generated\44\IdentityJsonSerializerContext.JsonElement.g.cs (8)
13private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.JsonElement>? _JsonElement; 19public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.JsonElement> JsonElement 22get => _JsonElement ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.JsonElement>)Options.GetTypeInfo(typeof(global::System.Text.Json.JsonElement)); 25private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.JsonElement> Create_JsonElement(global::System.Text.Json.JsonSerializerOptions options) 27if (!TryGetTypeInfoForRuntimeCustomConverter<global::System.Text.Json.JsonElement>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.JsonElement> jsonTypeInfo)) 29jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo<global::System.Text.Json.JsonElement>(options, global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.JsonElementConverter);
_generated\45\IdentityJsonSerializerContext.NullableJsonElement.g.cs (9)
13private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.JsonElement?>? _NullableJsonElement; 19public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.JsonElement?> NullableJsonElement 22get => _NullableJsonElement ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.JsonElement?>)Options.GetTypeInfo(typeof(global::System.Text.Json.JsonElement?)); 25private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.JsonElement?> Create_NullableJsonElement(global::System.Text.Json.JsonSerializerOptions options) 27if (!TryGetTypeInfoForRuntimeCustomConverter<global::System.Text.Json.JsonElement?>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.JsonElement?> jsonTypeInfo)) 29global::System.Text.Json.Serialization.JsonConverter converter = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.GetNullableConverter<global::System.Text.Json.JsonElement>(options); 30jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo<global::System.Text.Json.JsonElement?>(options, converter);
_generated\51\IdentityJsonSerializerContext.GetJsonTypeInfo.g.cs (2)
118if (type == typeof(global::System.Text.Json.JsonElement)) 122if (type == typeof(global::System.Text.Json.JsonElement?))
Passkeys\PublicKeyCredential.cs (1)
33public required JsonElement ClientExtensionResults { get; init; }
Passkeys\PublicKeyCredentialCreationOptions.cs (1)
69public JsonElement? Extensions { get; init; }
Passkeys\PublicKeyCredentialRequestOptions.cs (1)
49public JsonElement? Extensions { get; init; }
Microsoft.AspNetCore.Mvc.ViewFeatures (6)
Infrastructure\DefaultTempDataSerializer.cs (6)
21var rootElement = jsonDocument.RootElement; 25private static IDictionary<string, object> DeserializeDictionary(JsonElement rootElement) 80private static object DeserializeArray(in JsonElement arrayElement) 95foreach (var item in arrayElement.EnumerateArray()) 106foreach (var item in arrayElement.EnumerateArray()) 117private static object DeserializeDictionaryEntry(in JsonElement objectElement)
Microsoft.Build (3)
Construction\Solution\SolutionFile.cs (3)
634_solutionFile = ParseSolutionFromSolutionFilter(solutionFilterFile, out JsonElement solution); 648foreach (JsonElement project in solution.GetProperty("projects").EnumerateArray()) 665internal static string ParseSolutionFromSolutionFilter(string solutionFilterFile, out JsonElement solution)
Microsoft.CodeAnalysis.Features (1)
PdbSourceDocument\SourceLinkMap.cs (1)
72var root = JsonDocument.Parse(json, new JsonDocumentOptions() { AllowTrailingCommas = true }).RootElement;
Microsoft.CodeAnalysis.Workspaces.MSBuild (2)
MSBuild\SolutionFileReader.SolutionFilterReader.cs (2)
28var solution = document.RootElement.GetProperty("solution"); 51foreach (var project in solution.GetProperty("projects").EnumerateArray())
Microsoft.CodeAnalysis.Workspaces.MSBuild.Contracts (2)
Request.cs (1)
26public required JsonElement[] Parameters { get; init; }
Response.cs (1)
12public JsonElement? Value { get; init; }
Microsoft.Deployment.DotNet.Releases (34)
AspNetCoreReleaseComponent.cs (2)
43internal AspNetCoreReleaseComponent(JsonElement element, ProductRelease release) : base(element, release) 47if (element.TryGetProperty("version-aspnetcoremodule", out JsonElement ancmVersionValue) && ancmVersionValue.ValueKind != JsonValueKind.Null)
Cve.cs (3)
33/// Creates a new <see cref="Cve"/> instance from a <see cref="JsonElement"/>. 35/// <param name="cveElement">The <see cref="JsonElement"/> to deserialize.</param> 36internal Cve(JsonElement cveElement)
JsonExtensions.cs (9)
15/// <param name="value">The <see cref="JsonElement"/> to query.</param> 18internal static ReleaseVersion GetReleaseVersionOrDefault(this JsonElement value, string propertyName) 20if (value.TryGetProperty(propertyName, out JsonElement p) && p.ValueKind != JsonValueKind.Null) 32/// <param name="value">The <see cref="JsonElement"/> to query.</param> 35internal static string GetStringOrDefault(this JsonElement value, string propertyName) 37if (value.TryGetProperty(propertyName, out JsonElement p) && p.ValueKind == JsonValueKind.String) 49/// <param name="value">The <see cref="JsonElement"/> to query.</param> 52internal static Uri GetUriOrDefault(this JsonElement value, string propertyName) 54if (value.TryGetProperty(propertyName, out JsonElement p) && p.ValueKind != JsonValueKind.Null)
Product.cs (3)
148internal Product(JsonElement productElement) 150ReleaseType = productElement.TryGetProperty("release-type", out JsonElement value) ? 239JsonElement root = releasesDocument.RootElement;
ProductCollection.cs (2)
116var root = releasesIndexDocument.RootElement.GetProperty("releases-index"); 119using JsonElement.ArrayEnumerator enumerator = root.EnumerateArray();
ProductRelease.cs (7)
137internal ProductRelease(JsonElement element, Product product) 147if (element.TryGetProperty("cve-list", out JsonElement cveListElement) && cveListElement.ValueKind == JsonValueKind.Array) 161if (element.TryGetProperty("aspnetcore-runtime", out JsonElement aspNetCoreValue) && aspNetCoreValue.ValueKind != JsonValueKind.Null) 167if (element.TryGetProperty("runtime", out JsonElement runtimeValue) && runtimeValue.ValueKind != JsonValueKind.Null) 173if (element.TryGetProperty("windowsdesktop", out JsonElement desktopValue) && desktopValue.ValueKind != JsonValueKind.Null) 183if (element.TryGetProperty("sdks", out JsonElement sdksValue) && sdksValue.ValueKind == JsonValueKind.Array) 192else if (element.TryGetProperty("sdk", out JsonElement sdkValue) && sdkValue.ValueKind != JsonValueKind.Null)
ReleaseComponent.cs (2)
60internal ReleaseComponent(JsonElement element, ProductRelease release) 68if (element.TryGetProperty("files", out JsonElement P) && P.ValueKind == JsonValueKind.Array)
ReleaseFile.cs (3)
68/// Creates a new <see cref="ReleaseFile"/> instance from a <see cref="JsonElement"/>. 70/// <param name="fileElement">The <see cref="JsonElement"/> to deserialize.</param> 71internal ReleaseFile(JsonElement fileElement)
RuntimeReleaseComponent.cs (1)
42internal RuntimeReleaseComponent(JsonElement element, ProductRelease release) : base(element, release)
SdkReleaseComponent.cs (1)
88internal SdkReleaseComponent(JsonElement element, ProductRelease release) : base(element, release)
WindowsDesktopReleaseComponent.cs (1)
23internal WindowsDesktopReleaseComponent(JsonElement element, ProductRelease release) : base(element, release)
Microsoft.Diagnostics.DataContractReader (28)
_generated\0\ContractDescriptorContext.ContractDescriptor.g.cs (3)
173var info6 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.JsonElement>> 188AttributeProviderFactory = static () => typeof(global::Microsoft.Diagnostics.DataContractReader.ContractDescriptorParser.ContractDescriptor).GetProperty("Extras", InstanceMemberBindingFlags, null, typeof(global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.JsonElement>), global::System.Array.Empty<global::System.Type>(), null), 191properties[6] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.JsonElement>>(options, info6);
_generated\14\ContractDescriptorContext.GetJsonTypeInfo.g.cs (2)
52if (type == typeof(global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.JsonElement>)) 60if (type == typeof(global::System.Text.Json.JsonElement))
_generated\7\ContractDescriptorContext.DictionaryStringJsonElement.g.cs (13)
15private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.JsonElement>>? _DictionaryStringJsonElement; 21public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.JsonElement>> DictionaryStringJsonElement 24get => _DictionaryStringJsonElement ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.JsonElement>>)Options.GetTypeInfo(typeof(global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.JsonElement>)); 27private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.JsonElement>> Create_DictionaryStringJsonElement(global::System.Text.Json.JsonSerializerOptions options) 29if (!TryGetTypeInfoForRuntimeCustomConverter<global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.JsonElement>>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.JsonElement>> jsonTypeInfo)) 31var info = new global::System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues<global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.JsonElement>> 33ObjectCreator = () => new global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.JsonElement>(), 37jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateDictionaryInfo<global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.JsonElement>, string, global::System.Text.Json.JsonElement>(options, info); 47private void DictionaryStringJsonElementSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.JsonElement>? value) 57foreach (global::System.Collections.Generic.KeyValuePair<string, global::System.Text.Json.JsonElement> entry in value)
_generated\9\ContractDescriptorContext.JsonElement.g.cs (8)
15private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.JsonElement>? _JsonElement; 21public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.JsonElement> JsonElement 24get => _JsonElement ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.JsonElement>)Options.GetTypeInfo(typeof(global::System.Text.Json.JsonElement)); 27private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.JsonElement> Create_JsonElement(global::System.Text.Json.JsonSerializerOptions options) 29if (!TryGetTypeInfoForRuntimeCustomConverter<global::System.Text.Json.JsonElement>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.JsonElement> jsonTypeInfo)) 31jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo<global::System.Text.Json.JsonElement>(options, global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.JsonElementConverter);
ContractDescriptorParser.cs (2)
45[JsonSerializable(typeof(Dictionary<string, JsonElement>))] 73public Dictionary<string, JsonElement>? Extras { get; set; }
Microsoft.DotNet.Arcade.Sdk (3)
src\InstallDotNetCore.cs (3)
56if (jsonDocument.RootElement.TryGetProperty("tools", out JsonElement toolsElement)) 58if (toolsElement.TryGetProperty("runtimes", out JsonElement dotnetLocalElement)) 236foreach (var version in token.Value.EnumerateArray())
Microsoft.DotNet.ProjectTools (6)
LaunchSettings\LaunchSettings.cs (6)
88var model = document.RootElement; 90if (model.ValueKind != JsonValueKind.Object || !model.TryGetProperty(ProfilesKey, out var profilesObject) || profilesObject.ValueKind != JsonValueKind.Object) 96JsonElement profileObject; 134if (prop.Value.TryGetProperty(CommandNameKey, out var commandNameElement) && commandNameElement.ValueKind == JsonValueKind.String) 151if (!profileObject.TryGetProperty(CommandNameKey, out var finalCommandNameElement) 186|| !profileProperty.Value.TryGetProperty(CommandNameKey, out var commandNameElement)
Microsoft.Extensions.AI (9)
ChatCompletion\ChatClientStructuredOutputExtensions.cs (3)
154var schema = responseFormat.Schema!.Value; 203static bool SchemaRepresentsObject(JsonElement schemaElement) 220static JsonNode? JsonElementToJsonNode(JsonElement element) =>
ChatCompletion\ChatResponse{T}.cs (1)
139if (JsonDocument.Parse(json!).RootElement.TryGetProperty("data", out var data))
ChatCompletion\DistributedCachingChatClient.cs (1)
27/// will deserialize as <see cref="JsonElement"/> rather than as the original type. In general, code using <see cref="DistributedCachingChatClient"/>
ChatCompletion\DistributedCachingChatClientBuilderExtensions.cs (1)
32/// will deserialize as <see cref="JsonElement"/> rather than as the original type. In general, code using <see cref="DistributedCachingChatClient"/>
ChatCompletion\OpenTelemetryChatClient.cs (3)
463JsonElement element = _emptyObject; 942public JsonElement? Parameters { get; set; } 946private static readonly JsonElement _emptyObject = JsonSerializer.SerializeToElement(new object(), _defaultOptions.GetTypeInfo(typeof(object)));
Microsoft.Extensions.AI.Abstractions (50)
ChatCompletion\ChatResponseFormat.cs (2)
45JsonElement schema, string? schemaName = null, string? schemaDescription = null) => 84var schema = AIJsonUtilities.CreateJsonSchema(
ChatCompletion\ChatResponseFormatJson.cs (2)
21JsonElement? schema, string? schemaName = null, string? schemaDescription = null) 36public JsonElement? Schema { get; }
Functions\AIFunctionDeclaration.cs (2)
46public virtual JsonElement JsonSchema => AIJsonUtilities.DefaultJsonSchema; 53public virtual JsonElement? ReturnJsonSchema => null;
Functions\AIFunctionFactory.cs (24)
82/// invocation directly if the object is already of a compatible type. Otherwise, if the argument is a <see cref="JsonElement"/>, <see cref="JsonDocument"/>, 94/// By default, return values are serialized to <see cref="JsonElement"/> using <paramref name="options"/>'s 155/// invocation directly if the object is already of a compatible type. Otherwise, if the argument is a <see cref="JsonElement"/>, <see cref="JsonDocument"/>, 167/// Return values are serialized to <see cref="JsonElement"/> using <paramref name="serializerOptions"/> if provided, 240/// invocation directly if the object is already of a compatible type. Otherwise, if the argument is a <see cref="JsonElement"/>, <see cref="JsonDocument"/>, 252/// By default, return values are serialized to <see cref="JsonElement"/> using <paramref name="options"/>'s 320/// invocation directly if the object is already of a compatible type. Otherwise, if the argument is a <see cref="JsonElement"/>, <see cref="JsonDocument"/>, 332/// Return values are serialized to <see cref="JsonElement"/> using <paramref name="serializerOptions"/> if provided, 374/// Return values are serialized to <see cref="JsonElement"/> using <paramref name="options"/>'s 377/// <see cref="AIFunctionFactoryOptions.SerializerOptions"/>. If the argument is a <see cref="JsonElement"/>, 418/// invocation directly if the object is already of a compatible type. Otherwise, if the argument is a <see cref="JsonElement"/>, <see cref="JsonDocument"/>, 430/// By default, return values are serialized to <see cref="JsonElement"/> using <paramref name="options"/>'s 464JsonElement jsonSchema, 465JsonElement? returnJsonSchema = null) => 473string name, string description, JsonElement jsonSchema, JsonElement? returnJsonSchema) : 478public override JsonElement JsonSchema => jsonSchema; 479public override JsonElement? ReturnJsonSchema => returnJsonSchema; 555public override JsonElement JsonSchema => FunctionDescriptor.JsonSchema; 556public override JsonElement? ReturnJsonSchema => FunctionDescriptor.ReturnJsonSchema; 723public JsonElement JsonSchema { get; } 724public JsonElement? ReturnJsonSchema { get; } 843JsonElement element => JsonSerializer.Deserialize(element, typeInfo), 1071return JsonElement.ParseValue(ref reader);
Functions\AIFunctionFactoryOptions.cs (1)
80/// is then JSON serialized, with the resulting <see cref="JsonElement"/> returned from the <see cref="AIFunction.InvokeAsync"/> method.
Functions\DelegatingAIFunction.cs (2)
39public override JsonElement JsonSchema => InnerFunction.JsonSchema; 42public override JsonElement? ReturnJsonSchema => InnerFunction.ReturnJsonSchema;
Functions\DelegatingAIFunctionDeclaration.cs (2)
36public override JsonElement JsonSchema => InnerFunction.JsonSchema; 39public override JsonElement? ReturnJsonSchema => InnerFunction.ReturnJsonSchema;
Utilities\AIJsonSchemaTransformCache.cs (5)
61public JsonElement GetOrCreateTransformedSchema(AIFunction function) => 69public JsonElement GetOrCreateTransformedSchema(AIFunctionDeclaration function) 72return (JsonElement)_functionSchemaCache.GetValue(function, _functionSchemaCreateValueCallback); 80public JsonElement? GetOrCreateTransformedSchema(ChatResponseFormatJson responseFormat) 84? (JsonElement?)_responseFormatCache.GetValue(responseFormat, _responseFormatCreateValueCallback)
Utilities\AIJsonUtilities.Defaults.cs (1)
85[JsonSerializable(typeof(JsonElement))]
Utilities\AIJsonUtilities.Schema.Create.cs (7)
72/// <returns>A JSON schema document encoded as a <see cref="JsonElement"/>.</returns> 74public static JsonElement CreateFunctionJsonSchema( 182/// <returns>A <see cref="JsonElement"/> representing the schema.</returns> 183public static JsonElement CreateJsonSchema( 205internal static JsonElement DefaultJsonSchema { get; } = JsonElement.Parse("{}"u8); 208internal static void ValidateSchemaDocument(JsonElement document, [CallerArgumentExpression("document")] string? paramName = null)
Utilities\AIJsonUtilities.Schema.Transform.cs (2)
23public static JsonElement TransformSchema(JsonElement schema, AIJsonSchemaTransformOptions transformOptions)
Microsoft.Extensions.AI.Abstractions.Tests (111)
AssertExtensions.cs (6)
97public static void EqualJsonValues(JsonElement expectedJson, JsonElement actualJson, string? propertyName = null) 114JsonElement expectedElement = NormalizeToElement(expected, options); 115JsonElement actualElement = NormalizeToElement(actual, options); 118static JsonElement NormalizeToElement(object? value, JsonSerializerOptions options) 119=> value is JsonElement e ? e : JsonSerializer.SerializeToElement(value, options);
ChatCompletion\ChatOptionsTests.cs (2)
226Assert.IsType<JsonElement>(value); 227Assert.Equal("value", ((JsonElement)value!).GetString());
ChatCompletion\ChatResponseFormatTests.cs (3)
17private static JsonElement EmptySchema => JsonDocument.Parse("{}").RootElement; 79ChatResponseFormat.ForJsonSchema(JsonElement.Parse("[1,2,3]"), "name", "description"), 167JsonSerializer.Serialize(format.Schema, AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement))));
ChatCompletion\ChatResponseTests.cs (2)
115Assert.IsType<JsonElement>(value); 116Assert.Equal("value", ((JsonElement)value!).GetString());
ChatCompletion\ChatResponseUpdateTests.cs (2)
167Assert.IsType<JsonElement>(value); 168Assert.Equal("value", ((JsonElement)value!).GetString());
Contents\AIAnnotationTests.cs (1)
60Assert.Equal(JsonElement.Parse("\"value\"").ToString(), deserialized.AdditionalProperties["key"]!.ToString());
Contents\CitationAnnotationTests.cs (1)
86Assert.Equal(JsonElement.Parse("\"value\"").ToString(), deserialized.AdditionalProperties["key"]!.ToString());
Contents\FunctionCallContentTests.cs (5)
214Assert.All(arguments.Values, v => Assert.IsType<JsonElement>(v)); 358Assert.True(kvp.Value is JsonElement { ValueKind: JsonValueKind.Object }); 368Assert.True(kvp.Value is JsonElement { ValueKind: JsonValueKind.Array }); 373Assert.True(kvp.Value is JsonElement { ValueKind: JsonValueKind.Number }); 378Assert.True(kvp.Value is JsonElement { ValueKind: JsonValueKind.True });
Embeddings\EmbeddingGenerationOptionsTests.cs (2)
88Assert.IsType<JsonElement>(value); 89Assert.Equal("value", ((JsonElement)value!).GetString());
SpeechToText\SpeechToTextOptionsTests.cs (2)
87Assert.IsType<JsonElement>(value); 88Assert.Equal("value", ((JsonElement)value!).GetString());
SpeechToText\SpeechToTextResponseTests.cs (2)
184Assert.IsType<JsonElement>(value); 185Assert.Equal("value", ((JsonElement)value!).GetString());
test\Shared\JsonSchemaExporter\TestTypes.cs (4)
102yield return new TestData<JsonElement>(JsonDocument.Parse("""[{ "x" : 42 }]""").RootElement, "true"); 118yield return new TestData<JsonElement?>(JsonDocument.Parse("{}").RootElement, "true"); 1246[JsonSerializable(typeof(JsonElement))] 1260[JsonSerializable(typeof(JsonElement?))]
Utilities\AIJsonSchemaTransformCacheTests.cs (6)
52JsonElement transformedSchema = cache.GetOrCreateTransformedSchema(func); 55JsonElement transformedSchema2 = cache.GetOrCreateTransformedSchema(func); 64JsonElement schema = JsonDocument.Parse("{}").RootElement; 66JsonElement? transformedSchema = cache.GetOrCreateTransformedSchema(responseFormat); 70JsonElement? transformedSchema2 = cache.GetOrCreateTransformedSchema(responseFormat); 78JsonElement? transformedSchema = cache.GetOrCreateTransformedSchema(ChatResponseFormat.Json);
Utilities\AIJsonUtilitiesTests.cs (73)
152JsonElement expected = JsonDocument.Parse(""" 174JsonElement actual = AIJsonUtilities.CreateJsonSchema(typeof(MyPoco), serializerOptions: JsonContext.Default.Options); 182JsonElement expected = JsonDocument.Parse(""" 189JsonElement actual = AIJsonUtilities.CreateJsonSchema(typeof(object[]), serializerOptions: JsonContext.Default.Options); 197JsonElement expected = JsonDocument.Parse(""" 232JsonElement actual = AIJsonUtilities.CreateJsonSchema( 246JsonElement expected = JsonDocument.Parse(""" 282JsonElement actual = AIJsonUtilities.CreateJsonSchema(typeof(MyPoco), serializerOptions: JsonContext.Default.Options, inferenceOptions: inferenceOptions); 295JsonElement resolvedSchema = AIJsonUtilities.CreateFunctionJsonSchema(func.UnderlyingMethod, title: string.Empty); 322JsonElement expected = JsonDocument.Parse($$""" 358JsonElement resolvedSchema = AIJsonUtilities.CreateFunctionJsonSchema(func.UnderlyingMethod, title: string.Empty, description: string.Empty, inferenceOptions: inferenceOptions); 368JsonElement schemaParameters = func.JsonSchema.GetProperty("properties"); 388JsonElement expected = JsonDocument.Parse($$""" 394JsonElement actualSchema = property.Value; 434JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method, title: string.Empty); 436Assert.True(schema.TryGetProperty("required", out JsonElement requiredElement)); 496JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method, title: string.Empty, serializerOptions: options); 499Assert.True(schema.TryGetProperty("properties", out JsonElement properties)); 500Assert.True(properties.TryGetProperty("input", out JsonElement inputSchema)); 503Assert.True(inputSchema.TryGetProperty("required", out JsonElement requiredElement)); 515JsonElement schema = AIJsonUtilities.CreateJsonSchema(typeof(TypeWithRequiredMembers), serializerOptions: JsonContext.Default.Options); 517Assert.True(schema.TryGetProperty("required", out JsonElement requiredElement)); 557JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method); 560Assert.True(doc.RootElement.TryGetProperty("title", out JsonElement titleElement)); 562Assert.True(doc.RootElement.TryGetProperty("description", out JsonElement descElement)); 576JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method, title: "override_title"); 579Assert.True(doc.RootElement.TryGetProperty("title", out JsonElement titleElement)); 586JsonElement schema = AIJsonUtilities.CreateJsonSchema(typeof(object)); 605JsonElement schema = AIJsonUtilities.CreateJsonSchema(testData.Type, serializerOptions: options, inferenceOptions: createOptions); 630JsonElement schema = AIJsonUtilities.CreateJsonSchema(typeof(AIContent), serializerOptions: options); 640JsonElement expectedSchema = JsonDocument.Parse(""" 647JsonElement schema = AIJsonUtilities.CreateJsonSchema(typeof(MyEnumValue?), serializerOptions: JsonContext.Default.Options); 1135JsonElement expectedSchema = JsonDocument.Parse(""" 1148JsonElement actualSchema = AIJsonUtilities.CreateJsonSchema(typeof(ClassWithNullableMaxLengthProperty), serializerOptions: JsonContext.Default.Options); 1270JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method.Method, inferenceOptions: new() 1298JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method.Method, inferenceOptions: new() 1303JsonElement properties = schema.GetProperty("properties"); 1315JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method.Method, inferenceOptions: new() 1325JsonElement properties = schema.GetProperty("properties"); 1339JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method.Method, inferenceOptions: new() 1344JsonElement properties = schema.GetProperty("properties"); 1358JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method.Method, inferenceOptions: new() 1363JsonElement properties = schema.GetProperty("properties"); 1376JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method.Method, inferenceOptions: new() 1385JsonElement properties = schema.GetProperty("properties"); 1394JsonElement schema = JsonDocument.Parse(""" 1405JsonElement expectedSchema = JsonDocument.Parse(""" 1421JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options); 1428JsonElement schema = JsonDocument.Parse(""" 1439JsonElement expectedSchema = JsonDocument.Parse(""" 1455JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options); 1462JsonElement schema = JsonDocument.Parse(""" 1473JsonElement expectedSchema = JsonDocument.Parse(""" 1490JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options); 1497JsonElement schema = JsonDocument.Parse(""" 1509JsonElement expectedSchema = JsonDocument.Parse(""" 1527JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options); 1534JsonElement schema = JsonDocument.Parse(""" 1542JsonElement expectedSchema = JsonDocument.Parse(""" 1554JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options); 1573JsonElement schema = AIJsonUtilities.CreateJsonSchema(testData.Type, serializerOptions: options, inferenceOptions: createOptions); 1591JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, transformOptions); 1625JsonElement schema = JsonDocument.Parse("{}").RootElement; 1638JsonElement schema = JsonDocument.Parse(invalidSchema).RootElement; 1650JsonElement schema = JsonDocument.Parse(booleanSchema).RootElement; 1654JsonElement result = AIJsonUtilities.TransformSchema(schema, transformOptions); 1666Assert.True(result.TryGetProperty("not", out JsonElement notValue)); 1676[JsonSerializable(typeof(JsonElement))] 1686private static bool DeepEquals(JsonElement element1, JsonElement element2) 1688return JsonElement.DeepEquals(element1, element2); 1691private static void AssertDeepEquals(JsonElement element1, JsonElement element2)
Microsoft.Extensions.AI.Evaluation.Safety (4)
ContentSafetyService.cs (4)
59JsonElement metricElement = annotationResponseDocument.RootElement.EnumerateArray().Last(); 67JsonElement metricDetailsRootElement = metricDetailsDocument.RootElement; 69JsonElement labelElement = metricDetailsRootElement.GetProperty("label"); 277foreach (JsonElement element in document.RootElement.EnumerateArray())
Microsoft.Extensions.AI.Integration.Tests (7)
ChatClientIntegrationTests.cs (2)
521public override JsonElement JsonSchema { get; } = JsonElement.Parse(jsonSchema);
PromptBasedFunctionCallingChatClient.cs (1)
153if (kvp.Value is JsonElement jsonElement)
VerbatimMultiPartHttpHandler.cs (4)
119((List<JsonElement>)parameters[name]).Add(ParseContentToJsonElement(rawValue)); 123parameters.Add(name, new List<JsonElement> { ParseContentToJsonElement(rawValue) }); 132if (parameters[key] is List<JsonElement> list && list.Count == 1) 151private static JsonElement ParseContentToJsonElement(string content)
Microsoft.Extensions.AI.OpenAI (5)
MicrosoftExtensionsAIChatExtensions.cs (1)
246return JsonElement.Parse(ms.GetBuffer().AsSpan(0, (int)ms.Position));
OpenAIClientExtensions.cs (3)
193JsonElement jsonSchema = strict is true ? 275public Dictionary<string, JsonElement> Properties { get; set; } = []; 281public Dictionary<string, JsonElement>? ExtensionData { get; set; }
OpenAIJsonContext.cs (1)
23[JsonSerializable(typeof(JsonElement))]
Microsoft.Extensions.AI.OpenAI.Tests (30)
OpenAIConversionTests.cs (16)
113var jsonSchema = JsonDocument.Parse(""" 144var root = parsedParams.RootElement; 146Assert.True(root.TryGetProperty("$defs", out var defs), "The $defs property should be preserved in the function parameters"); 147Assert.True(defs.TryGetProperty("Person", out var person), "The Person definition should exist in $defs"); 148Assert.True(person.TryGetProperty("properties", out var properties), "Person should have properties"); 623var root = jsonDoc.RootElement; 626Assert.True(root.TryGetProperty("properties", out var properties)); 627Assert.True(properties.TryGetProperty("name", out var nameProperty)); 687Assert.True(JsonElement.DeepEquals(JsonSerializer.SerializeToElement(new Dictionary<string, object?> 691}), JsonElement.Parse(tc.FunctionArguments.ToMemory().Span))); 743Assert.True(JsonElement.DeepEquals(JsonSerializer.SerializeToElement(new Dictionary<string, object?> 747}), JsonElement.Parse(m3.FunctionArguments.ToMemory().Span))); 1080Assert.Equal(42, ((JsonElement)deserializedArgs["number"]!).GetInt32()); 1081Assert.True(((JsonElement)deserializedArgs["boolean"]!).GetBoolean()); 1084var nestedObj = (JsonElement)deserializedArgs["nestedObject"]!;
OpenAIResponseClientTests.cs (8)
1550Assert.Equal("dotnet/extensions", ((JsonElement)call.Arguments["repoName"]!).GetString()); 1551Assert.Equal("What is the path to the README.md file for Microsoft.Extensions.AI.Abstractions?", ((JsonElement)call.Arguments["question"]!).GetString()); 1805Assert.Equal("dotnet/extensions", ((JsonElement)firstCall.Arguments["repoName"]!).GetString()); 1817Assert.Equal("dotnet/extensions", ((JsonElement)secondCall.Arguments["repoName"]!).GetString()); 1818Assert.Equal("What is the path to the README.md file for Microsoft.Extensions.AI.Abstractions?", ((JsonElement)secondCall.Arguments["question"]!).GetString()); 2218Assert.Equal("dotnet/extensions", ((JsonElement)firstCall.Arguments["repoName"]!).GetString()); 2230Assert.Equal("dotnet/extensions", ((JsonElement)secondCall.Arguments["repoName"]!).GetString()); 2231Assert.Equal("What is the path to the README.md file for Microsoft.Extensions.AI.Abstractions?", ((JsonElement)secondCall.Arguments["question"]!).GetString());
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\AssertExtensions.cs (6)
97public static void EqualJsonValues(JsonElement expectedJson, JsonElement actualJson, string? propertyName = null) 114JsonElement expectedElement = NormalizeToElement(expected, options); 115JsonElement actualElement = NormalizeToElement(actual, options); 118static JsonElement NormalizeToElement(object? value, JsonSerializerOptions options) 119=> value is JsonElement e ? e : JsonSerializer.SerializeToElement(value, options);
Microsoft.Extensions.AI.Tests (44)
ChatCompletion\ChatClientStructuredOutputExtensionsTests.cs (5)
470private static void AssertDeepEquals(JsonElement element1, JsonElement element2) 483private static bool DeepEquals(JsonElement element1, JsonElement element2) 485return JsonElement.DeepEquals(element1, element2);
ChatCompletion\FunctionInvokingChatClientTests.cs (1)
346return result is JsonElement e ?
Functions\AIFunctionFactoryTest.cs (31)
159AIFunction func = AIFunctionFactory.Create((JsonElement param) => param, serializerOptions: options); 160JsonElement expectedResult = JsonDocument.Parse(jsonStringParam, new() { CommentHandling = JsonCommentHandling.Skip }).RootElement; 179AIFunction func = AIFunctionFactory.Create((JsonElement param) => param); 180JsonElement expectedResult = JsonDocument.Parse(JsonSerializer.Serialize(invalidJsonParam, JsonContext.Default.String)).RootElement; 376var result = (JsonElement?)await func.InvokeAsync(new() 1004JsonElement expectedSchema = JsonDocument.Parse(""" 1037JsonElement expectedSchema = JsonDocument.Parse(""" 1074JsonElement schema = AIJsonUtilities.CreateJsonSchema(typeof(int), serializerOptions: AIJsonUtilities.DefaultOptions); 1326JsonElement schema = func.JsonSchema; 1327JsonElement properties = schema.GetProperty("properties"); 1330JsonElement nullableIntSchema = properties.GetProperty("nullableInt"); 1332nullableIntSchema.TryGetProperty("type", out JsonElement nullableIntType), 1339JsonElement nullableIntWithDefaultSchema = properties.GetProperty("nullableIntWithDefault"); 1341nullableIntWithDefaultSchema.TryGetProperty("type", out JsonElement nullableIntWithDefaultType), 1347nullableIntWithDefaultSchema.TryGetProperty("default", out JsonElement nullableIntWithDefaultDefault), 1352JsonElement required = schema.GetProperty("required"); 1366JsonElement schema = func.JsonSchema; 1367JsonElement properties = schema.GetProperty("properties"); 1370JsonElement nullableStringSchema = properties.GetProperty("nullableString"); 1372nullableStringSchema.TryGetProperty("type", out JsonElement nullableStringType), 1379JsonElement nullableIntSchema = properties.GetProperty("nullableInt"); 1381nullableIntSchema.TryGetProperty("type", out JsonElement nullableIntType), 1388JsonElement nullableStringWithDefaultSchema = properties.GetProperty("nullableStringWithDefault"); 1390nullableStringWithDefaultSchema.TryGetProperty("type", out JsonElement nullableStringWithDefaultType), 1396nullableStringWithDefaultSchema.TryGetProperty("default", out JsonElement nullableStringWithDefaultDefault), 1401JsonElement nullableIntWithDefaultSchema = properties.GetProperty("nullableIntWithDefault"); 1403nullableIntWithDefaultSchema.TryGetProperty("type", out JsonElement nullableIntWithDefaultType), 1409nullableIntWithDefaultSchema.TryGetProperty("default", out JsonElement nullableIntWithDefaultDefault), 1414JsonElement required = schema.GetProperty("required"); 1446JsonElement schema = func.JsonSchema; 1447JsonElement properties = schema.GetProperty("properties");
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\AssertExtensions.cs (6)
97public static void EqualJsonValues(JsonElement expectedJson, JsonElement actualJson, string? propertyName = null) 114JsonElement expectedElement = NormalizeToElement(expected, options); 115JsonElement actualElement = NormalizeToElement(actual, options); 118static JsonElement NormalizeToElement(object? value, JsonSerializerOptions options) 119=> value is JsonElement e ? e : JsonSerializer.SerializeToElement(value, options);
TestJsonSerializerContext.cs (1)
20[JsonSerializable(typeof(JsonElement))]
Microsoft.Extensions.Configuration.Json (4)
JsonConfigurationFileParser.cs (4)
43private void VisitObjectElement(JsonElement element) 58private void VisitArrayElement(JsonElement element) 62foreach (JsonElement arrayElement in element.EnumerateArray()) 89private void VisitValue(JsonElement value)
Microsoft.ML.GenAI.Phi (4)
Module\Phi3SuScaledRotaryEmbedding.cs (4)
28JsonElement shortFactorElement = (JsonElement)config.RopeScaling!["short_factor"]; 29JsonElement longFactorDocument = (JsonElement)config.RopeScaling!["long_factor"];
Microsoft.ML.Tokenizers.Tests (29)
BpeTests.cs (25)
956JsonElement root = doc.RootElement; 957if (!root.TryGetProperty("model", out JsonElement modelElement) || 959!modelElement.TryGetProperty("type", out JsonElement typeElement) || 961!modelElement.TryGetProperty("vocab", out JsonElement vocabElement) || 969if (modelElement.TryGetProperty("unk_token", out JsonElement unKnownElement)) 974if (modelElement.TryGetProperty("continuing_subword_prefix", out JsonElement continuingSubwordPrefixElement)) 979if (modelElement.TryGetProperty("end_of_word_suffix", out JsonElement endOfWordSuffixElement)) 984if (modelElement.TryGetProperty("fuse_unknown_tokens", out JsonElement fuseUnknownTokensElement)) 1004private static IEnumerable<KeyValuePair<string, int>> GetVocabulary(JsonElement vocabElement) 1012private static IEnumerable<string> GetMerges(JsonElement modelElement) 1014if (modelElement.TryGetProperty("merges", out JsonElement mergesElement) && mergesElement.ValueKind == JsonValueKind.Array) 1016foreach (JsonElement merge in mergesElement.EnumerateArray()) 1028private static IReadOnlyList<PreTokenizer>? GetPreTokenizer(JsonElement root, out bool byteLevel) 1033if (root.TryGetProperty("pre_tokenizer", out JsonElement preTokenizerElement) && 1035preTokenizerElement.TryGetProperty("type", out JsonElement typeElement) && 1038preTokenizerElement.TryGetProperty("pretokenizers", out JsonElement preTokenizersElement) && 1041foreach (JsonElement preTokenizer in preTokenizersElement.EnumerateArray()) 1044preTokenizer.TryGetProperty("type", out JsonElement preTokenizerTypeElement) && 1050if (preTokenizer.TryGetProperty("pattern", out JsonElement patternElement) && 1052patternElement.TryGetProperty("Regex", out JsonElement regexElement) && 1073private static Dictionary<string, int>? GetSpecialTokens(JsonElement root) 1075if (root.TryGetProperty("added_tokens", out JsonElement modelElement) && modelElement.ValueKind == JsonValueKind.Array) 1078foreach (JsonElement token in modelElement.EnumerateArray()) 1080if (token.TryGetProperty("content", out JsonElement contentElement) && 1082token.TryGetProperty("id", out JsonElement idElement) && idElement.ValueKind == JsonValueKind.Number)
UnigramTests.cs (4)
30private static IEnumerable<(string Token, float Score)> GetVocabulary(JsonElement root) 32if (root.TryGetProperty("model", out JsonElement modelElement) && 33modelElement.TryGetProperty("vocab", out JsonElement vocabElement) && 36foreach (JsonElement token in vocabElement.EnumerateArray())
Microsoft.NET.Build.Containers (13)
LocalDaemons\DockerCli.cs (13)
249if (!config.RootElement.TryGetProperty("ServerErrors", out JsonElement errorProperty)) 332var rootElement = GetDockerConfig().RootElement; 335if (rootElement.TryGetProperty("RegistryConfig", out var registryConfig) && registryConfig.ValueKind == JsonValueKind.Object) 337if (registryConfig.TryGetProperty("IndexConfigs", out var indexConfigs) && indexConfigs.ValueKind == JsonValueKind.Object) 342&& property.Value.TryGetProperty("Secure", out var secure) 353if (rootElement.TryGetProperty("registries", out var registries) && registries.ValueKind == JsonValueKind.Object) 358&& property.Value.TryGetProperty("Insecure", out var insecure) 706var dockerinfo = GetDockerConfig().RootElement; 710dockerinfo.TryGetProperty("DockerRootDir", out var dockerRootDir) && dockerRootDir.GetString() is not null; 711var hasPodmanProperty = dockerinfo.TryGetProperty("host", out var host) && host.TryGetProperty("buildahVersion", out var buildahVersion) && buildahVersion.GetString() is not null; 725if (!GetDockerConfig().RootElement.TryGetProperty("DriverStatus", out var driverStatus) || driverStatus.ValueKind != JsonValueKind.Array) 730foreach (var item in driverStatus.EnumerateArray())
Microsoft.NET.HostModel (2)
ComHost\RegFreeComManifest.cs (2)
57JsonElement clsidMap; 68if (property.Value.TryGetProperty("progid", out JsonElement progIdValue))
Microsoft.SourceLink.Tools.Package (1)
SourceLinkMap.cs (1)
92var root = JsonDocument.Parse(json, new JsonDocumentOptions() { AllowTrailingCommas = true }).RootElement;
Microsoft.TemplateEngine.Edge (1)
src\sdk\src\TemplateEngine\Shared\JExtensions.cs (1)
255/// <see cref="JsonObject.WriteTo"/> falls back to the underlying <see cref="System.Text.Json.JsonElement"/>
Microsoft.TemplateEngine.Utils (1)
src\sdk\src\TemplateEngine\Shared\JExtensions.cs (1)
255/// <see cref="JsonObject.WriteTo"/> falls back to the underlying <see cref="System.Text.Json.JsonElement"/>
Microsoft.TemplateSearch.Common (1)
src\sdk\src\TemplateEngine\Shared\JExtensions.cs (1)
255/// <see cref="JsonObject.WriteTo"/> falls back to the underlying <see cref="System.Text.Json.JsonElement"/>
Microsoft.TestPlatform.CommunicationUtilities (103)
JsonDataSerializer.Stj.cs (5)
82var root = doc.RootElement; 83int version = root.TryGetProperty("Version", out var vProp) 86string? messageType = root.TryGetProperty("MessageType", out var mtProp) ? mtProp.GetString() : null; 106if (doc.RootElement.TryGetProperty("Payload", out var payloadElement)) 191var serializedPayload = JsonSerializer.SerializeToElement(payload, payloadOptions);
Serialization\AfterTestRunEndResultConverter.cs (3)
32var root = doc.RootElement; 51private static T? DeserializeProperty<T>(JsonElement element, string name, JsonSerializerOptions options) 53if (element.TryGetProperty(name, out var prop) && prop.ValueKind != JsonValueKind.Null)
Serialization\AttachmentConverters.cs (5)
23var element = doc.RootElement; 29if (element.TryGetProperty("Attachments", out var attachments) && attachments.GetArrayLength() > 0) 31foreach (var attachment in attachments.EnumerateArray()) 63var element = doc.RootElement; 66var description = element.TryGetProperty("Description", out var descProp) && descProp.ValueKind != JsonValueKind.Null
Serialization\DiscoveryCriteriaConverter.cs (6)
31var root = doc.RootElement; 36var runSettings = root.TryGetProperty("RunSettings", out var rs) && rs.ValueKind != JsonValueKind.Null ? rs.GetString() : null; 37var package = root.TryGetProperty("Package", out var pkg) && pkg.ValueKind != JsonValueKind.Null ? pkg.GetString() : null; 38var testCaseFilter = root.TryGetProperty("TestCaseFilter", out var tcf) && tcf.ValueKind != JsonValueKind.Null ? tcf.GetString() : null; 74private static T? DeserializeProperty<T>(JsonElement element, string name, JsonSerializerOptions options) 76if (element.TryGetProperty(name, out var prop) && prop.ValueKind != JsonValueKind.Null)
Serialization\TestCaseConverter.cs (5)
26var data = doc.RootElement; 28if (!data.TryGetProperty("Properties", out var properties) || properties.GetArrayLength() == 0) 35foreach (var property in properties.EnumerateArray()) 37if (!property.TryGetProperty("Key", out var keyElement)) 50if (!property.TryGetProperty("Value", out var token))
Serialization\TestCaseConverterV2.cs (12)
27var data = doc.RootElement; 29if (data.TryGetProperty("FullyQualifiedName", out var fqn)) 31if (data.TryGetProperty("ExecutorUri", out var uri) && uri.ValueKind != JsonValueKind.Null) 33if (data.TryGetProperty("Source", out var source)) 35if (data.TryGetProperty("Id", out var id) && id.ValueKind != JsonValueKind.Null) 37if (data.TryGetProperty("DisplayName", out var display) && display.ValueKind != JsonValueKind.Null) 39if (data.TryGetProperty("CodeFilePath", out var codePath) && codePath.ValueKind != JsonValueKind.Null) 41if (data.TryGetProperty("LineNumber", out var lineNum)) 45if (data.TryGetProperty("Properties", out var properties) && properties.GetArrayLength() > 0) 47foreach (var prop in properties.EnumerateArray()) 49if (!prop.TryGetProperty("Key", out var keyElement)) 56if (!prop.TryGetProperty("Value", out var valueElement))
Serialization\TestExecutionContextConverter.cs (9)
24var data = doc.RootElement; 28if (data.TryGetProperty("FrequencyOfRunStatsChangeEvent", out var freq)) 30if (data.TryGetProperty("RunStatsChangeEventTimeout", out var timeout)) 32if (data.TryGetProperty("InIsolation", out var isolation)) 34if (data.TryGetProperty("KeepAlive", out var keepAlive)) 36if (data.TryGetProperty("AreTestCaseLevelEventsRequired", out var tcEvents)) 38if (data.TryGetProperty("IsDebug", out var isDebug)) 40if (data.TryGetProperty("TestCaseFilter", out var filter) && filter.ValueKind != JsonValueKind.Null) 42if (data.TryGetProperty("FilterOptions", out var filterOptions) && filterOptions.ValueKind != JsonValueKind.Null)
Serialization\TestObjectBaseConverter.cs (5)
44var data = doc.RootElement; 46if (!data.TryGetProperty("Properties", out var properties) || properties.GetArrayLength() == 0) 51foreach (var prop in properties.EnumerateArray()) 53if (!prop.TryGetProperty("Key", out var keyElement)) 60if (!prop.TryGetProperty("Value", out var valueElement))
Serialization\TestObjectConverter.cs (3)
39var element = doc.RootElement; 41if (!element.TryGetProperty("Key", out var keyElement)) 49if (element.TryGetProperty("Value", out var valueElement) && valueElement.ValueKind != JsonValueKind.Null)
Serialization\TestProcessAttachDebuggerPayloadConverter.cs (3)
29var root = doc.RootElement; 31var processId = root.TryGetProperty("ProcessID", out var pidProp) ? pidProp.GetInt32() : 0; 32var targetFramework = root.TryGetProperty("TargetFramework", out var tf) && tf.ValueKind != JsonValueKind.Null
Serialization\TestPropertyConverter.cs (7)
29var element = doc.RootElement; 31var id = element.TryGetProperty("Id", out var idProp) ? idProp.GetString() : null; 32var label = element.TryGetProperty("Label", out var labelProp) ? labelProp.GetString() : null; 33var category = element.TryGetProperty("Category", out var catProp) ? catProp.GetString() : null; 34var description = element.TryGetProperty("Description", out var descProp) ? descProp.GetString() : null; 35var attributes = element.TryGetProperty("Attributes", out var attrProp) ? (TestPropertyAttributes)attrProp.GetInt32() : default; 36var valueType = element.TryGetProperty("ValueType", out var vtProp) ? vtProp.GetString() : null;
Serialization\TestResultConverter.cs (9)
24var data = doc.RootElement; 26var testCaseElement = data.GetProperty("TestCase"); 31if (data.TryGetProperty("Attachments", out var attachments) && attachments.GetArrayLength() > 0) 33foreach (var attachment in attachments.EnumerateArray()) 43if (data.TryGetProperty("Messages", out var messages) && messages.GetArrayLength() > 0) 45foreach (var message in messages.EnumerateArray()) 54if (!data.TryGetProperty("Properties", out var properties) || properties.GetArrayLength() == 0) 61foreach (var property in properties.EnumerateArray()) 66var token = property.GetProperty("Value");
Serialization\TestResultConverterV2.cs (18)
26var data = doc.RootElement; 29var testCaseElement = data.GetProperty("TestCase"); 34if (data.TryGetProperty("Attachments", out var attachments) && attachments.GetArrayLength() > 0) 36foreach (var attachment in attachments.EnumerateArray()) 46if (data.TryGetProperty("Messages", out var messages) && messages.GetArrayLength() > 0) 48foreach (var message in messages.EnumerateArray()) 58if (data.TryGetProperty("Outcome", out var outcome)) 60if (data.TryGetProperty("ErrorMessage", out var errorMsg) && errorMsg.ValueKind != JsonValueKind.Null) 62if (data.TryGetProperty("ErrorStackTrace", out var errorStack) && errorStack.ValueKind != JsonValueKind.Null) 64if (data.TryGetProperty("DisplayName", out var displayName) && displayName.ValueKind != JsonValueKind.Null) 66if (data.TryGetProperty("ComputerName", out var computerName) && computerName.ValueKind != JsonValueKind.Null) 68if (data.TryGetProperty("Duration", out var duration) && duration.ValueKind != JsonValueKind.Null) 70if (data.TryGetProperty("StartTime", out var startTime) && startTime.ValueKind != JsonValueKind.Null) 72if (data.TryGetProperty("EndTime", out var endTime) && endTime.ValueKind != JsonValueKind.Null) 76if (data.TryGetProperty("Properties", out var properties) && properties.GetArrayLength() > 0) 78foreach (var prop in properties.EnumerateArray()) 80if (!prop.TryGetProperty("Key", out var keyElement)) 85if (!prop.TryGetProperty("Value", out var valueElement))
Serialization\TestRunChangedEventArgsConverter.cs (3)
31var root = doc.RootElement; 50private static T? DeserializeProperty<T>(JsonElement element, string name, JsonSerializerOptions options) 52if (element.TryGetProperty(name, out var prop) && prop.ValueKind != JsonValueKind.Null)
Serialization\TestRunCompleteEventArgsConverter.cs (5)
32var root = doc.RootElement; 35var isCanceled = root.TryGetProperty("IsCanceled", out var ic) && ic.GetBoolean(); 36var isAborted = root.TryGetProperty("IsAborted", out var ia) && ia.GetBoolean(); 65private static T? DeserializeProperty<T>(JsonElement element, string name, JsonSerializerOptions options) 67if (element.TryGetProperty(name, out var prop) && prop.ValueKind != JsonValueKind.Null)
Serialization\TestRunStatisticsConverter.cs (3)
27var root = doc.RootElement; 29long executedTests = root.TryGetProperty("ExecutedTests", out var etProp) ? etProp.GetInt64() : 0; 32if (root.TryGetProperty("Stats", out var statsProp) && statsProp.ValueKind == JsonValueKind.Object)
Serialization\TestSessionInfoConverter.cs (2)
29var root = doc.RootElement; 31var id = root.TryGetProperty("Id", out var idProp) && idProp.ValueKind != JsonValueKind.Null
Microsoft.TestPlatform.TestHostRuntimeProvider (3)
Hosting\DotnetTestHostManager.cs (3)
958var runtimeOptions = doc.RootElement.GetProperty("runtimeOptions"); 959var additionalProbingPaths = runtimeOptions.GetProperty("additionalProbingPaths"); 960foreach (var x in additionalProbingPaths.EnumerateArray())
NuGet.Protocol (6)
Plugins\MessageConverter.cs (6)
14private static readonly Dictionary<(MessageMethod, MessageType), Func<JsonElement, object?>> _read = new() 106var root = doc.RootElement; 108if (!root.TryGetProperty(nameof(Message.RequestId), out var requestIdProp)) 119if (!root.TryGetProperty(nameof(Message.Type), out var typeProp)) 130if (!root.TryGetProperty(nameof(Message.Method), out var methodProp)) 142if (root.TryGetProperty("Payload", out var payloadProp) && payloadProp.ValueKind != JsonValueKind.Null)
rzc (6)
Json\JsonDataReader.cs (6)
15/// <see cref="JsonElement"/> from System.Text.Json, providing 20private readonly JsonElement _element; 21private JsonElement _currentValue; 23public JsonDataReader(JsonElement element) 165foreach (var item in _currentValue.EnumerateArray()) 182foreach (var item in _currentValue.EnumerateArray())
Shared.Tests (4)
JsonSchemaExporter\TestTypes.cs (4)
102yield return new TestData<JsonElement>(JsonDocument.Parse("""[{ "x" : 42 }]""").RootElement, "true"); 118yield return new TestData<JsonElement?>(JsonDocument.Parse("{}").RootElement, "true"); 1246[JsonSerializable(typeof(JsonElement))] 1260[JsonSerializable(typeof(JsonElement?))]
System.Text.Json (212)
System\Runtime\InteropServices\JsonMarshal.cs (2)
14/// Gets a <see cref="ReadOnlySpan{T}"/> view over the raw JSON data of the given <see cref="JsonElement"/>. 25public static ReadOnlySpan<byte> GetRawUtf8Value(JsonElement element)
System\Text\Json\Document\JsonDocument.cs (8)
33/// The <see cref="JsonElement"/> representing the value of the document. 35public JsonElement RootElement => new JsonElement(this, 0); 99/// This <see cref="RootElement"/>'s <see cref="JsonElement.ValueKind"/> would result in an invalid JSON. 151internal JsonElement GetArrayIndexElement(int currentIndex, int arrayIndex) 712internal JsonElement CloneElement(int index) 1056JsonElement curr = new JsonElement(document, traversalPath.Peek()); 1062JsonElement.ObjectEnumerator enumerator = new(curr, databaseIndexOflastProcessedChild ?? -1); 1089JsonElement.ArrayEnumerator enumerator = new(curr, databaseIndexOflastProcessedChild ?? -1);
System\Text\Json\Document\JsonDocument.TryGetProperty.cs (3)
11internal unsafe bool TryGetNamedPropertyValue(int index, ReadOnlySpan<char> propertyName, out JsonElement value) 111internal bool TryGetNamedPropertyValue(int index, ReadOnlySpan<byte> propertyName, out JsonElement value) 139out JsonElement value)
System\Text\Json\Document\JsonElement.ArrayEnumerator.cs (7)
16public struct ArrayEnumerator : IEnumerable<JsonElement>, IEnumerator<JsonElement> 18private readonly JsonElement _target; 22internal ArrayEnumerator(JsonElement target, int currentIndex = -1) 33public JsonElement Current 64IEnumerator<JsonElement> IEnumerable<JsonElement>.GetEnumerator() => GetEnumerator();
System\Text\Json\Document\JsonElement.cs (27)
63public JsonElement this[int index] 108/// Gets a <see cref="JsonElement"/> representing the value of a required property identified 119/// A <see cref="JsonElement"/> representing the value of the requested property. 134public JsonElement GetProperty(string propertyName) 138if (TryGetProperty(propertyName, out JsonElement property)) 147/// Gets a <see cref="JsonElement"/> representing the value of a required property identified 162/// A <see cref="JsonElement"/> representing the value of the requested property. 174public JsonElement GetProperty(ReadOnlySpan<char> propertyName) 176if (TryGetProperty(propertyName, out JsonElement property)) 185/// Gets a <see cref="JsonElement"/> representing the value of a required property identified 202/// A <see cref="JsonElement"/> representing the value of the requested property. 214public JsonElement GetProperty(ReadOnlySpan<byte> utf8PropertyName) 216if (TryGetProperty(utf8PropertyName, out JsonElement property)) 254public bool TryGetProperty(string propertyName, out JsonElement value) 288public bool TryGetProperty(ReadOnlySpan<char> propertyName, out JsonElement value) 324public bool TryGetProperty(ReadOnlySpan<byte> utf8PropertyName, out JsonElement value) 1238/// Compares the values of two <see cref="JsonElement"/> values for equality, including the values of all descendant elements. 1240/// <param name="element1">The first <see cref="JsonElement"/> to compare.</param> 1241/// <param name="element2">The second <see cref="JsonElement"/> to compare.</param> 1258public static bool DeepEquals(JsonElement element1, JsonElement element2) 1304foreach (JsonElement e1 in element1.EnumerateArray()) 1368Dictionary<string, ValueQueue<JsonElement>> properties2 = new(capacity: remainingProps, StringComparer.Ordinal); 1373ref ValueQueue<JsonElement> values = ref CollectionsMarshal.GetValueRefOrAddDefault(properties2, prop2.Name, out bool _); 1388ref ValueQueue<JsonElement> values = ref CollectionsMarshal.GetValueRefOrAddDefault(properties2, prop.Name, out bool exists); 1392if (!exists || !values.TryDequeue(out JsonElement value) || !DeepEquals(prop.Value, value)) 1693public JsonElement Clone()
System\Text\Json\Document\JsonElement.ObjectEnumerator.cs (2)
18private readonly JsonElement _target; 22internal ObjectEnumerator(JsonElement target, int currentIndex = -1)
System\Text\Json\Document\JsonElement.Parse.cs (13)
47public static JsonElement ParseValue(ref Utf8JsonReader reader) 56internal static JsonElement ParseValue(ref Utf8JsonReader reader, bool allowDuplicateProperties) 70internal static JsonElement ParseValue(Stream utf8Json, JsonDocumentOptions options) 77/// Parses UTF8-encoded text representing a single JSON value into a <see cref="JsonElement"/>. 81/// <returns>A <see cref="JsonElement"/> representation of the JSON value.</returns> 84public static JsonElement Parse([StringSyntax(StringSyntaxAttribute.Json)] ReadOnlySpan<byte> utf8Json, JsonDocumentOptions options = default) 91/// Parses text representing a single JSON value into a <see cref="JsonElement"/>. 95/// <returns>A <see cref="JsonElement"/> representation of the JSON value.</returns> 98public static JsonElement Parse([StringSyntax(StringSyntaxAttribute.Json)] ReadOnlySpan<char> json, JsonDocumentOptions options = default) 105/// Parses text representing a single JSON value into a <see cref="JsonElement"/>. 109/// <returns>A <see cref="JsonElement"/> representation of the JSON value.</returns> 113public static JsonElement Parse([StringSyntax(StringSyntaxAttribute.Json)] string json, JsonDocumentOptions options = default) 159public static bool TryParseValue(ref Utf8JsonReader reader, [NotNullWhen(true)] out JsonElement? element)
System\Text\Json\Document\JsonProperty.cs (3)
18public JsonElement Value { get; } 20internal JsonProperty(JsonElement value) 110/// This <see cref="Value"/>'s <see cref="JsonElement.ValueKind"/> would result in an invalid JSON.
System\Text\Json\Nodes\JsonArray.cs (13)
23private JsonElement? _jsonElement; 26internal override JsonElement? UnderlyingElement => _jsonElement; 76GetUnderlyingRepresentation(out List<JsonNode?>? list, out JsonElement? jsonElement); 183/// Initializes a new instance of the <see cref="JsonArray"/> class that contains items from the specified <see cref="JsonElement"/>. 186/// The new instance of the <see cref="JsonArray"/> class that contains items from the specified <see cref="JsonElement"/>. 188/// <param name="element">The <see cref="JsonElement"/>.</param> 193public static JsonArray? Create(JsonElement element, JsonNodeOptions? options = null) 203internal JsonArray(JsonElement element, JsonNodeOptions? options = null) : base(options) 268GetUnderlyingRepresentation(out List<JsonNode?>? list, out JsonElement? jsonElement); 296GetUnderlyingRepresentation(out List<JsonNode?>? list, out JsonElement? jsonElement); 302JsonElement jElement = jsonElement.Value; 307foreach (JsonElement element in jElement.EnumerateArray()) 332private void GetUnderlyingRepresentation(out List<JsonNode?>? list, out JsonElement? jsonElement)
System\Text\Json\Nodes\JsonNode.cs (6)
28internal virtual JsonElement? UnderlyingElement => null; 185/// If the underlying value is a <see cref="JsonElement"/> then {T} can also be the type of any primitive 186/// value supported by current <see cref="JsonElement"/>. 188/// The underlying value of a <see cref="JsonValue"/> after deserialization is an instance of <see cref="JsonElement"/>, 369/// to support arbitrary <see cref="JsonElement"/> and <see cref="JsonNode"/> values. 386if (value is JsonElement element)
System\Text\Json\Nodes\JsonNode.Parse.cs (8)
51JsonElement element = JsonElement.ParseValue(ref reader); 77JsonElement element = JsonElement.Parse(json, documentOptions); 98JsonElement element = JsonElement.Parse(utf8Json, documentOptions); 122JsonElement element = JsonElement.ParseValue(utf8Json, documentOptions);
System\Text\Json\Nodes\JsonObject.cs (10)
21private JsonElement? _jsonElement; 23internal override JsonElement? UnderlyingElement => _jsonElement; 51/// Initializes a new instance of the <see cref="JsonObject"/> class that contains properties from the specified <see cref="JsonElement"/>. 54/// The new instance of the <see cref="JsonObject"/> class that contains properties from the specified <see cref="JsonElement"/>. 56/// <param name="element">The <see cref="JsonElement"/>.</param> 59public static JsonObject? Create(JsonElement element, JsonNodeOptions? options = null) 69internal JsonObject(JsonElement element, JsonNodeOptions? options = null) : this(options) 85GetUnderlyingRepresentation(out OrderedDictionary<string, JsonNode?>? dictionary, out JsonElement? jsonElement); 165GetUnderlyingRepresentation(out OrderedDictionary<string, JsonNode?>? dictionary, out JsonElement? jsonElement); 187GetUnderlyingRepresentation(out OrderedDictionary<string, JsonNode?>? dictionary, out JsonElement? jsonElement);
System\Text\Json\Nodes\JsonObject.IDictionary.cs (2)
249GetUnderlyingRepresentation(out OrderedDictionary<string, JsonNode?>? dictionary, out JsonElement? jsonElement); 298private void GetUnderlyingRepresentation(out OrderedDictionary<string, JsonNode?>? dictionary, out JsonElement? jsonElement)
System\Text\Json\Nodes\JsonValue.CreateOverloads.cs (3)
290public static JsonValue? Create(JsonElement value, JsonNodeOptions? options = null) => JsonValue.CreateFromElement(ref value, options); 298public static JsonValue? Create(JsonElement? value, JsonNodeOptions? options = null) => value is JsonElement element ? JsonValue.CreateFromElement(ref element, options) : null;
System\Text\Json\Nodes\JsonValue.cs (10)
26/// If the underlying value is a <see cref="JsonElement"/> then {T} can also be the type of any primitive 27/// value supported by current <see cref="JsonElement"/>. 29/// The underlying value of a <see cref="JsonValue"/> after deserialization is an instance of <see cref="JsonElement"/>, 62if (value is JsonElement element) 98if (value is JsonElement element && jsonTypeInfo.EffectiveConverter.IsInternalConverter) 114JsonElement thisElement = ToJsonElement(this, out JsonDocument? thisDocument); 115JsonElement otherElement = ToJsonElement(otherNode, out JsonDocument? otherDocument); 118return JsonElement.DeepEquals(thisElement, otherElement); 126static JsonElement ToJsonElement(JsonNode node, out JsonDocument? backingDocument) 178internal static JsonValue? CreateFromElement(ref readonly JsonElement element, JsonNodeOptions? options = null)
System\Text\Json\Nodes\JsonValueOfElement.cs (6)
10/// Defines a primitive JSON value that is wrapping a <see cref="JsonElement"/>. 12internal sealed class JsonValueOfElement : JsonValue<JsonElement> 14public JsonValueOfElement(JsonElement value, JsonNodeOptions? options) : base(value, options) 19internal override JsonElement? UnderlyingElement => Value; 25if (otherNode.UnderlyingElement is JsonElement otherElement) 27return JsonElement.DeepEquals(Value, otherElement);
System\Text\Json\Nodes\JsonValueOfJsonPrimitive.cs (9)
69if (typeof(T) == typeof(JsonElement) || typeof(T) == typeof(JsonElement?) || typeof(T) == typeof(object)) 71value = (T)(object)JsonWriterHelper.WriteString(_value.Span, static serialized => JsonElement.Parse(serialized)); 153if (typeof(T) == typeof(JsonElement) || typeof(T) == typeof(JsonElement?) || typeof(T) == typeof(object)) 155value = (T)(object)JsonElement.Parse(_value ? JsonConstants.TrueValue : JsonConstants.FalseValue); 200if (typeof(T) == typeof(JsonElement) || typeof(T) == typeof(JsonElement?) || typeof(T) == typeof(object)) 202value = (T)(object)JsonElement.Parse(_value);
System\Text\Json\Nodes\JsonValueOfT.cs (2)
18Debug.Assert(value is not JsonElement or JsonElement { ValueKind: not JsonValueKind.Null });
System\Text\Json\Serialization\Attributes\JsonExtensionDataAttribute.cs (4)
15/// and TValue must be <see cref="JsonElement"/> or <see cref="object"/>. 19/// <see cref="JsonElement"/> depending on the value of <see cref="System.Text.Json.JsonSerializerOptions.UnknownTypeHandling"/>. 21/// If a <see cref="JsonElement"/> is created, a "null" JSON value is treated as a JsonElement with <see cref="JsonElement.ValueKind"/>
System\Text\Json\Serialization\Converters\Node\JsonArrayConverter.cs (2)
40JsonElement jElement = JsonElement.ParseValue(ref reader);
System\Text\Json\Serialization\Converters\Node\JsonNodeConverter.cs (1)
79public static JsonNode? Create(JsonElement element, JsonNodeOptions? options)
System\Text\Json\Serialization\Converters\Node\JsonObjectConverter.cs (2)
78JsonElement jElement = JsonElement.ParseValue(ref reader);
System\Text\Json\Serialization\Converters\Node\JsonValueConverter.cs (2)
38JsonElement element = JsonElement.ParseValue(ref reader, options.AllowDuplicateProperties);
System\Text\Json\Serialization\Converters\Object\ObjectConverter.cs (3)
101return JsonElement.ParseValue(ref reader, options.AllowDuplicateProperties); 114JsonElement element = JsonElement.ParseValue(ref reader, options.AllowDuplicateProperties);
System\Text\Json\Serialization\Converters\Object\ObjectWithParameterizedConstructorConverter.cs (3)
241if (extDictionary is IDictionary<string, JsonElement> dict) 245dict[dataExtKey] = (JsonElement)propValue!; 247else if (!dict.TryAdd(dataExtKey, (JsonElement)propValue!))
System\Text\Json\Serialization\Converters\Value\JsonElementConverter.cs (4)
9internal sealed class JsonElementConverter : JsonConverter<JsonElement> 11public override JsonElement Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 13return JsonElement.ParseValue(ref reader, options.AllowDuplicateProperties); 16public override void Write(Utf8JsonWriter writer, JsonElement value, JsonSerializerOptions options)
System\Text\Json\Serialization\JsonSerializer.Read.Element.cs (15)
13/// Converts the <see cref="JsonElement"/> representing a single JSON value into a <typeparamref name="TValue"/>. 17/// <param name="element">The <see cref="JsonElement"/> to convert.</param> 28public static TValue? Deserialize<TValue>(this JsonElement element, JsonSerializerOptions? options = null) 36/// Converts the <see cref="JsonElement"/> representing a single JSON value into a <paramref name="returnType"/>. 39/// <param name="element">The <see cref="JsonElement"/> to convert.</param> 54public static object? Deserialize(this JsonElement element, Type returnType, JsonSerializerOptions? options = null) 64/// Converts the <see cref="JsonElement"/> representing a single JSON value into a <typeparamref name="TValue"/>. 68/// <param name="element">The <see cref="JsonElement"/> to convert.</param> 80public static TValue? Deserialize<TValue>(this JsonElement element, JsonTypeInfo<TValue> jsonTypeInfo) 90/// Converts the <see cref="JsonElement"/> representing a single JSON value into an instance specified by the <paramref name="jsonTypeInfo"/>. 93/// <param name="element">The <see cref="JsonElement"/> to convert.</param> 98public static object? Deserialize(this JsonElement element, JsonTypeInfo jsonTypeInfo) 108/// Converts the <see cref="JsonElement"/> representing a single JSON value into a <paramref name="returnType"/>. 111/// <param name="element">The <see cref="JsonElement"/> to convert.</param> 139public static object? Deserialize(this JsonElement element, Type returnType, JsonSerializerContext context)
System\Text\Json\Serialization\JsonSerializer.Read.HandleMetadata.cs (1)
398JsonElement element,
System\Text\Json\Serialization\JsonSerializer.Read.HandlePropertyName.cs (7)
117jsonPropertyInfo.PropertyType == typeof(IReadOnlyDictionary<string, JsonElement>); 133genericArgs[1].UnderlyingSystemType == typeof(JsonElement) || 169else if (jsonPropertyInfo.PropertyType == typeof(IReadOnlyDictionary<string, JsonElement>)) 173var existing = (IReadOnlyDictionary<string, JsonElement>)extensionData; 174var newDict = new Dictionary<string, JsonElement>(); 175foreach (KeyValuePair<string, JsonElement> kvp in existing) 183extensionData = new Dictionary<string, JsonElement>();
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());
System\Text\Json\Serialization\Metadata\JsonMetadataServices.Converters.cs (3)
140/// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="JsonElement"/> values. 143public static JsonConverter<JsonElement> JsonElementConverter => s_jsonElementConverter ??= new JsonElementConverter(); 144private static JsonConverter<JsonElement>? s_jsonElementConverter;
System\Text\Json\Serialization\Metadata\JsonPropertyInfo.cs (10)
866else if (propValue is IDictionary<string, JsonElement> dictionaryElementValue) 868JsonConverter<JsonElement> converter = GetDictionaryValueConverter<JsonElement>(); 869JsonElement value = converter.Read(ref reader, typeof(JsonElement), Options); 933JsonConverter<JsonElement> converter = (JsonConverter<JsonElement>)Options.GetConverterInternal(typeof(JsonElement)); 934if (!converter.TryRead(ref reader, typeof(JsonElement), Options, ref state, out JsonElement jsonElement, out _))
System\Text\Json\Serialization\Metadata\JsonTypeInfo.cs (2)
1789typeof(IDictionary<string, JsonElement>).IsAssignableFrom(propertyType) || 1791propertyType == typeof(IReadOnlyDictionary<string, JsonElement>) ||