10 instantiations of JsonElement
Microsoft.AspNetCore.Components.WebAssembly.Server (1)
Microsoft.Build (1)
System.Text.Json (8)
1896 references to JsonElement
aspire (145)
DotNet\DotNetCliRunner.cs (12)
710var rootElement = jsonDocument.RootElement;
712if (!rootElement.TryGetProperty("Properties", out var properties))
717if (!properties.TryGetProperty("IsAspireHost", out var isAspireHostElement))
727if (rootElement.TryGetProperty("Items", out var items))
730if (items.TryGetProperty("PackageReference", out var packageReferences))
737if (aspireHostingVersion == null && items.TryGetProperty("AspireProjectOrPackageReference", out var aspireProjectOrPackageReferences))
744if (aspireHostingVersion == null && items.TryGetProperty("PackageVersion", out var packageVersions))
752if (aspireHostingVersion == null && properties.TryGetProperty("AspireHostingSDKVersion", out var aspireHostingSdkVersionElement))
770private static string? GetPackageVersion(JsonElement items, string packageId)
772foreach (var item in items.EnumerateArray())
774if (item.TryGetProperty("Identity", out var identity) &&
776item.TryGetProperty("Version", out var version))
Npm\SigstoreNpmProvenanceChecker.cs (10)
393if (predicate.TryGetProperty("buildDefinition", out var buildDefinition) &&
396if (buildDefinition.TryGetProperty("buildType", out var buildTypeElement) &&
402if (buildDefinition.TryGetProperty("externalParameters", out var extParams) &&
404extParams.TryGetProperty("workflow", out var workflow) &&
407if (workflow.TryGetProperty("repository", out var repoEl) &&
413if (workflow.TryGetProperty("path", out var pathEl) &&
419if (workflow.TryGetProperty("ref", out var refEl) &&
427if (predicate.TryGetProperty("runDetails", out var runDetails) &&
429runDetails.TryGetProperty("builder", out var builder) &&
432if (builder.TryGetProperty("id", out var idEl) &&
aspire-managed (12)
Aspire.Azure.Npgsql (6)
Aspire.Azure.Npgsql.EntityFrameworkCore.PostgreSQL (6)
Aspire.Cli.EndToEnd.Tests (41)
SmokeTests.cs (9)
287var root = config.RootElement;
289var sdk = GetRequiredJsonObjectProperty(root, "sdk", configPath);
297var appHost = GetRequiredJsonObjectProperty(root, "appHost", configPath);
309private static JsonElement GetRequiredJsonObjectProperty(JsonElement element, string propertyName, string configPath)
311if (!element.TryGetProperty(propertyName, out var property) ||
320private static void AssertJsonStringProperty(JsonElement element, string propertyName, string expectedValue, string configPath)
329private static string GetRequiredJsonStringProperty(JsonElement element, string propertyName, string configPath)
331if (!element.TryGetProperty(propertyName, out var property) ||
Aspire.Cli.Tests (112)
Commands\DoctorCommandTests.cs (33)
50var cliVersionCheck = GetCheckByName(doc, AspireVersionCheck.CliVersionCheckName);
55var cliVersionMetadata = cliVersionCheck.GetProperty("metadata");
71var osCheck = GetCheckByName(doc, OperatingSystemCheck.CheckName);
75var metadata = osCheck.GetProperty("metadata");
98var osCheck = GetCheckByName(doc, OperatingSystemCheck.CheckName);
99var metadata = osCheck.GetProperty("metadata");
179var appHostVersionCheck = GetCheckByName(doc, AspireVersionCheck.AppHostVersionCheckName);
184var appHostVersionMetadata = appHostVersionCheck.GetProperty("metadata");
228var appHostVersionCheck = GetCheckByName(doc, AspireVersionCheck.AppHostVersionCheckName);
233var appHostVersionMetadata = appHostVersionCheck.GetProperty("metadata");
366var cliVersionCheck = GetCheckByName(doc, AspireVersionCheck.CliVersionCheckName);
367var appHostVersionCheck = GetCheckByName(doc, AspireVersionCheck.AppHostVersionCheckName);
392var cliVersionCheck = GetCheckByName(doc, AspireVersionCheck.CliVersionCheckName);
393var appHostVersionCheck = GetCheckByName(doc, AspireVersionCheck.AppHostVersionCheckName);
426var appHostVersionCheck = GetCheckByName(doc, AspireVersionCheck.AppHostVersionCheckName);
431var appHostVersionMetadata = appHostVersionCheck.GetProperty("metadata");
459var cliVersionCheck = GetCheckByName(doc, AspireVersionCheck.CliVersionCheckName);
460var metadata = cliVersionCheck.GetProperty("metadata");
485var cliVersionCheck = GetCheckByName(doc, AspireVersionCheck.CliVersionCheckName);
486var metadata = cliVersionCheck.GetProperty("metadata");
515var appHostVersionCheck = GetCheckByName(doc, AspireVersionCheck.AppHostVersionCheckName);
516var metadata = appHostVersionCheck.GetProperty("metadata");
549var appHostVersionCheck = GetCheckByName(doc, AspireVersionCheck.AppHostVersionCheckName);
550var metadata = appHostVersionCheck.GetProperty("metadata");
574var appHostVersionCheck = GetCheckByName(doc, AspireVersionCheck.AppHostVersionCheckName);
575var metadata = appHostVersionCheck.GetProperty("metadata");
607var cliVersionCheck = GetCheckByName(doc, AspireVersionCheck.CliVersionCheckName);
610var metadata = cliVersionCheck.GetProperty("metadata");
663var self = installations[0];
669var peer = installations[1];
894var row = Assert.Single(installations);
922var row = Assert.Single(doc.RootElement.GetProperty("installations").EnumerateArray());
1031private static JsonElement GetCheckByName(JsonDocument document, string checkName)
Mcp\ListConsoleLogsToolTests.cs (13)
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>
220var arguments = new Dictionary<string, JsonElement>
254var arguments = new Dictionary<string, JsonElement>
286var arguments = new Dictionary<string, JsonElement>
320var arguments = new Dictionary<string, JsonElement>
355var arguments = new Dictionary<string, JsonElement>
392var arguments = new Dictionary<string, JsonElement>
429var arguments = new Dictionary<string, JsonElement>
Aspire.Dashboard (3)
Aspire.Dashboard.Tests (13)
Aspire.Deployment.EndToEnd.Tests (16)
Aspire.Hosting (36)
Dcp\DcpLogParser.cs (6)
179var root = doc.RootElement;
194("Cmd", root.TryGetProperty("Cmd", out var cmdProp) ? cmdProp.GetString() : null),
195("Args", root.TryGetProperty("Args", out var argsProp) ? argsProp.ToString() : null),
196("ContainerName", root.TryGetProperty("ContainerName", out var containerNameProp) ? containerNameProp.GetString() : null),
197("ContainerId", root.TryGetProperty("ContainerID", out var containerIdProp) ? containerIdProp.GetString() : null),
198("Error", root.TryGetProperty("error", out var errorProp) ? errorProp.GetString() : null)
Aspire.Hosting.Azure (4)
Aspire.Hosting.Azure.Tests (11)
Aspire.Hosting.Blazor (13)
Aspire.Hosting.Browsers (10)
ChromiumBrowserResolver.cs (10)
119internal static string? TryResolveProfileDirectory(JsonElement localStateRoot, string userDataDirectory, string profile)
124if (!localStateRoot.TryGetProperty("profile", out var profileElement) ||
125!profileElement.TryGetProperty("info_cache", out var infoCacheElement) ||
279private static void AddProfilesFromLocalState(JsonElement localStateRoot, string userDataDirectory, Dictionary<string, ChromiumBrowserProfile> profiles)
281if (!localStateRoot.TryGetProperty("profile", out var profileElement) ||
282!profileElement.TryGetProperty("info_cache", out var infoCacheElement) ||
320private static bool MatchesBrowserProfileProperty(JsonElement profileElement, string propertyName, string profile)
322return profileElement.TryGetProperty(propertyName, out var propertyElement) &&
327private static string? TryGetProfileProperty(JsonElement profileElement, string propertyName)
329return profileElement.TryGetProperty(propertyName, out var propertyElement) &&
Aspire.Hosting.Browsers.Tests (18)
src\Aspire.Hosting.Browsers\ChromiumBrowserResolver.cs (10)
119internal static string? TryResolveProfileDirectory(JsonElement localStateRoot, string userDataDirectory, string profile)
124if (!localStateRoot.TryGetProperty("profile", out var profileElement) ||
125!profileElement.TryGetProperty("info_cache", out var infoCacheElement) ||
279private static void AddProfilesFromLocalState(JsonElement localStateRoot, string userDataDirectory, Dictionary<string, ChromiumBrowserProfile> profiles)
281if (!localStateRoot.TryGetProperty("profile", out var profileElement) ||
282!profileElement.TryGetProperty("info_cache", out var infoCacheElement) ||
320private static bool MatchesBrowserProfileProperty(JsonElement profileElement, string propertyName, string profile)
322return profileElement.TryGetProperty(propertyName, out var propertyElement) &&
327private static string? TryGetProfileProperty(JsonElement profileElement, string propertyName)
329return profileElement.TryGetProperty(propertyName, out var propertyElement) &&
Aspire.Hosting.CodeGeneration.TypeScript (1)
Aspire.Hosting.CodeGeneration.TypeScript.Tests (3)
Aspire.Hosting.Dotnet (1)
Aspire.Hosting.EntityFrameworkCore (4)
Aspire.Hosting.Foundry (15)
Aspire.Hosting.Java.Tests (3)
Aspire.Hosting.JavaScript (1)
Aspire.Hosting.Kubernetes (36)
KubernetesEnvironmentResource.cs (24)
1728if (doc.RootElement.TryGetProperty("status", out var status) &&
1729status.TryGetProperty("addresses", out var addresses))
1732foreach (var addr in addresses.EnumerateArray())
1734if (addr.TryGetProperty("type", out var type) &&
1736addr.TryGetProperty("value", out var value))
1747foreach (var addr in addresses.EnumerateArray())
1749if (addr.TryGetProperty("value", out var value))
1803if (doc.RootElement.TryGetProperty("spec", out var spec) &&
1804spec.TryGetProperty("listeners", out var listeners))
1808var listener = listeners[i];
1809if (listener.TryGetProperty("protocol", out var protocol) &&
1983private static List<int> FindForeignListenerOwnershipIndices(System.Text.Json.JsonElement root)
1987if (!root.TryGetProperty("metadata", out var metadata) ||
1988!metadata.TryGetProperty("managedFields", out var managedFields) ||
1996var entry = managedFields[i];
2000if (!entry.TryGetProperty("operation", out var op) ||
2008if (entry.TryGetProperty("manager", out var mgr) &&
2018if (entry.TryGetProperty("fieldsV1", out var fieldsV1) &&
2019fieldsV1.TryGetProperty("f:spec", out var fSpec) &&
2071var root = doc.RootElement;
2081if (root.TryGetProperty("metadata", out var metadata))
2083if (metadata.TryGetProperty("annotations", out var annotations))
2088if (metadata.TryGetProperty("labels", out var labels))
2102if (root.TryGetProperty("spec", out var spec))
Aspire.Hosting.Maui (3)
Aspire.Hosting.OpenAI (3)
Aspire.Hosting.PostgreSQL.Tests (1)
Aspire.Hosting.Radius (27)
Publishing\SealedSecretApplyStep.cs (14)
420if (document.RootElement.TryGetProperty("metadata", out var metadata) &&
421metadata.TryGetProperty("generation", out var generation) &&
436var root = document.RootElement;
439if (root.TryGetProperty("metadata", out var metadata) &&
440metadata.TryGetProperty("generation", out var generationElement) &&
448if (root.TryGetProperty("status", out var status))
450if (status.TryGetProperty("observedGeneration", out var observedGenerationElement) &&
456if (status.TryGetProperty("conditions", out var conditionsElement) &&
459foreach (var condition in conditionsElement.EnumerateArray())
461var type = condition.TryGetProperty("type", out var typeElement) && typeElement.ValueKind == JsonValueKind.String
464var conditionStatus = condition.TryGetProperty("status", out var statusElement) && statusElement.ValueKind == JsonValueKind.String
473var message = condition.TryGetProperty("message", out var messageElement) && messageElement.ValueKind == JsonValueKind.String
600var root = document.RootElement;
604if (root.TryGetProperty(property, out var element) && element.ValueKind == JsonValueKind.Object)
Secrets\SealedSecretManifest.cs (13)
370var root = document.RootElement;
383JsonElement? kind = null;
384JsonElement data = default;
385JsonElement stringData = default;
448private static bool SealedSecretTemplateHasPlaintext(JsonElement root)
450if (!TryGetSingleObjectProperty(root, "spec", out var spec, out var specDuplicated))
455if (!TryGetSingleObjectProperty(spec, "template", out var template, out var templateDuplicated))
463private static bool TemplateFieldHasPlaintext(JsonElement template, string field)
465JsonElement value = default;
489private static bool TryGetSingleObjectProperty(JsonElement obj, string name, out JsonElement value, out bool duplicated)
511private static bool HasNonEmptyValue(JsonElement element)
523private static bool HasAnyChild(JsonElement obj)
Aspire.Hosting.Radius.Tests (1)
Aspire.Hosting.RemoteHost (10)
Aspire.Hosting.RemoteHost.Tests (5)
CodeGeneration\ApiReferenceExportTests.cs (4)
30var export = service.ExportApi("TypeScript", "Aspire.Hosting", "13.5.0", CancellationToken.None);
31var repeatedExport = service.ExportApi("TypeScript", "Aspire.Hosting", "13.5.0", CancellationToken.None);
60var export = service.ExportApi("TypeScript", "Aspire.Hosting", "13.5.0", CancellationToken.None);
143var export = service.ExportApi("TypeScript", "contoso.aspire.metapackage", "1.2.3", CancellationToken.None);
Aspire.Hosting.Rust (17)
CargoMetadata.cs (17)
77var root = document.RootElement;
80if (root.TryGetProperty("packages", out var packagesElement) && packagesElement.ValueKind == JsonValueKind.Array)
82foreach (var packageElement in packagesElement.EnumerateArray())
88if (!root.TryGetProperty("workspace_default_members", out var defaultMembersElement)
100TargetDirectory = root.TryGetProperty("target_directory", out var targetDirectoryElement)
106private static CargoPackage ParsePackage(JsonElement element)
109if (element.TryGetProperty("targets", out var targetsElement) && targetsElement.ValueKind == JsonValueKind.Array)
111foreach (var targetElement in targetsElement.EnumerateArray())
113if (IsBinTarget(targetElement) && targetElement.TryGetProperty("name", out var targetName)
123Name = element.TryGetProperty("name", out var nameElement) ? nameElement.GetString() ?? string.Empty : string.Empty,
124Id = element.TryGetProperty("id", out var idElement) ? idElement.GetString() ?? string.Empty : string.Empty,
125DefaultRun = element.TryGetProperty("default_run", out var defaultRunElement) && defaultRunElement.ValueKind == JsonValueKind.String
132private static bool IsBinTarget(JsonElement targetElement)
134if (!targetElement.TryGetProperty("kind", out var kindElement) || kindElement.ValueKind != JsonValueKind.Array)
139foreach (var kind in kindElement.EnumerateArray())
150private static List<string> ReadStringArray(JsonElement element)
156foreach (var item in element.EnumerateArray())
Aspire.Hosting.Sdk.Tests (1)
Aspire.Hosting.Seq.Tests (2)
Aspire.Hosting.Tests (46)
Aspire.Templates.Tests (2)
Aspire.TestTools (14)
Aspire.TypeSystem (2)
dotnet-aot (11)
dotnet-openapi (1)
dotnet-sourcelink (1)
dotnet-user-jwts (8)
DotNetInvocationHostedAgent (2)
ILCompiler.Compiler (1)
ILCompiler.ReadyToRun (4)
Infrastructure.Tests (78)
tools\GenerateCITimeline\TimelineRenderer.cs (13)
173private static DateTimeOffset? ParseTs(JsonElement element, string property)
175if (element.TryGetProperty(property, out var val) && val.ValueKind == JsonValueKind.String)
186private static string GetString(JsonElement element, string property, string defaultValue = "")
188if (element.TryGetProperty(property, out var val) && val.ValueKind == JsonValueKind.String)
195private static int GetInt(JsonElement element, string property, int defaultValue = 0)
197if (element.TryGetProperty(property, out var val) && val.ValueKind == JsonValueKind.Number)
204private static List<string> GetLabels(JsonElement job)
207if (job.TryGetProperty("labels", out var arr) && arr.ValueKind == JsonValueKind.Array)
209foreach (var item in arr.EnumerateArray())
220private static List<JobGroup> BuildJobGroups(List<JsonElement> jobs, DateTimeOffset t0)
224foreach (var raw in jobs)
456public static string GenerateSummary(JsonElement runInfo, List<JsonElement> jobs, double minTotalMinutes = 0)
WorkflowScripts\AutoRerunTransientCiFailuresTests.cs (20)
1248JsonElement root = doc.RootElement;
1251Assert.True(root.TryGetProperty("version", out JsonElement version));
1253Assert.True(root.TryGetProperty("testFailurePatterns", out JsonElement testPatterns));
1255Assert.True(root.TryGetProperty("jobFailurePatterns", out JsonElement jobPatterns));
1272JsonElement root = doc.RootElement;
1279foreach (JsonElement rule in root.GetProperty("testFailurePatterns").EnumerateArray())
1284foreach (JsonElement rule in root.GetProperty("jobFailurePatterns").EnumerateArray())
1310JsonElement root = doc.RootElement;
2078private static void ValidatePatternRule(JsonElement rule, HashSet<string> allowedFields, HashSet<string> matcherFields)
2088rule.TryGetProperty("reason", out JsonElement reason) && reason.ValueKind == JsonValueKind.String && reason.GetString()!.Length > 0,
2091if (rule.TryGetProperty("enabled", out JsonElement enabled))
2101if (rule.TryGetProperty(field, out JsonElement fieldValue))
2111private static void ValidatePatternValue(JsonElement value, string fieldName)
2122value.TryGetProperty("regex", out JsonElement regex) && regex.ValueKind == JsonValueKind.String && regex.GetString()!.Length > 0,
2130private static void ExtractRegexPatterns(JsonElement patternsArray, List<string> regexPatterns)
2132foreach (JsonElement rule in patternsArray.EnumerateArray())
2137prop.Value.TryGetProperty("regex", out JsonElement regex) &&
2330public JsonElement[][] Rows { get; init; } = [];
2357public JsonElement Payload { get; init; }
2362public JsonElement? Config { get; init; }
Microsoft.AspNetCore.Authentication (4)
Microsoft.AspNetCore.Authentication.DeviceBoundSessions (2)
Microsoft.AspNetCore.Authentication.OAuth (24)
Microsoft.AspNetCore.Authentication.OpenIdConnect (1)
Microsoft.AspNetCore.Authentication.Twitter (5)
Microsoft.AspNetCore.Components.AI (1)
Microsoft.AspNetCore.Components.Endpoints (46)
Generated\361d1da7f942c932\BrowserOptionsJsonContext.IDictionaryStringJsonElement.g.cs (13)
13private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IDictionary<string, global::System.Text.Json.JsonElement>>? _IDictionaryStringJsonElement;
19public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IDictionary<string, global::System.Text.Json.JsonElement>> IDictionaryStringJsonElement
22get => _IDictionaryStringJsonElement ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IDictionary<string, global::System.Text.Json.JsonElement>>)Options.GetTypeInfo(typeof(global::System.Collections.Generic.IDictionary<string, global::System.Text.Json.JsonElement>));
25private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IDictionary<string, global::System.Text.Json.JsonElement>> Create_IDictionaryStringJsonElement(global::System.Text.Json.JsonSerializerOptions options)
27if (!TryGetTypeInfoForRuntimeCustomConverter<global::System.Collections.Generic.IDictionary<string, global::System.Text.Json.JsonElement>>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IDictionary<string, global::System.Text.Json.JsonElement>> jsonTypeInfo))
29var info = new global::System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues<global::System.Collections.Generic.IDictionary<string, global::System.Text.Json.JsonElement>>
31ObjectCreator = () => new global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.JsonElement>(),
37jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateIDictionaryInfo<global::System.Collections.Generic.IDictionary<string, global::System.Text.Json.JsonElement>, string, global::System.Text.Json.JsonElement>(options, info);
47private void IDictionaryStringJsonElementSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::System.Collections.Generic.IDictionary<string, global::System.Text.Json.JsonElement>? value)
57foreach (global::System.Collections.Generic.KeyValuePair<string, global::System.Text.Json.JsonElement> entry in value)
Generated\361d1da7f942c932\BrowserOptionsJsonContext.InteractiveServerBrowserOptions.g.cs (3)
113var info3 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::System.Collections.Generic.IDictionary<string, global::System.Text.Json.JsonElement>>
128AttributeProviderFactory = static () => typeof(global::Microsoft.AspNetCore.Components.InteractiveServerBrowserOptions).GetProperty("Extensions", InstanceMemberBindingFlags, null, typeof(global::System.Collections.Generic.IDictionary<string, global::System.Text.Json.JsonElement>), global::System.Array.Empty<global::System.Type>(), null),
131properties[3] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::System.Collections.Generic.IDictionary<string, global::System.Text.Json.JsonElement>>(options, info3);
src\aspnetcore\src\Components\Shared\src\RenderFragmentSerializer.cs (6)
274builder.SetKey(node.Key is JsonElement je ? ConvertTypedValue(je, node.KeyTypeAssembly!, node.KeyTypeName!, jsonOptions, typeCache) : node.Key);
301builder.SetKey(node.Key is JsonElement je ? ConvertTypedValue(je, node.KeyTypeAssembly!, node.KeyTypeName!, jsonOptions, typeCache) : node.Key);
333var value = attr.Value is JsonElement je
361JsonElement je => JsonSerializer.Deserialize<SerializedRenderFragment>(je.GetRawText(), jsonOptions),
368return attr.Value is JsonElement json ? ConvertTypedValue(json, attr.TypeAssembly!, attr.TypeName!, jsonOptions, typeCache) : attr.Value;
372private static object? ConvertTypedValue(JsonElement json, string assemblyName, string typeName, JsonSerializerOptions? jsonOptions, ComponentParametersTypeCache typeCache)
Microsoft.AspNetCore.Components.Server (14)
src\aspnetcore\src\Components\Shared\src\RenderFragmentSerializer.cs (6)
274builder.SetKey(node.Key is JsonElement je ? ConvertTypedValue(je, node.KeyTypeAssembly!, node.KeyTypeName!, jsonOptions, typeCache) : node.Key);
301builder.SetKey(node.Key is JsonElement je ? ConvertTypedValue(je, node.KeyTypeAssembly!, node.KeyTypeName!, jsonOptions, typeCache) : node.Key);
333var value = attr.Value is JsonElement je
361JsonElement je => JsonSerializer.Deserialize<SerializedRenderFragment>(je.GetRawText(), jsonOptions),
368return attr.Value is JsonElement json ? ConvertTypedValue(json, attr.TypeAssembly!, attr.TypeName!, jsonOptions, typeCache) : attr.Value;
372private static object? ConvertTypedValue(JsonElement json, string assemblyName, string typeName, JsonSerializerOptions? jsonOptions, ComponentParametersTypeCache typeCache)
Microsoft.AspNetCore.Components.Web (46)
Microsoft.AspNetCore.Components.WebAssembly (22)
src\aspnetcore\src\Components\Shared\src\RenderFragmentSerializer.cs (6)
274builder.SetKey(node.Key is JsonElement je ? ConvertTypedValue(je, node.KeyTypeAssembly!, node.KeyTypeName!, jsonOptions, typeCache) : node.Key);
301builder.SetKey(node.Key is JsonElement je ? ConvertTypedValue(je, node.KeyTypeAssembly!, node.KeyTypeName!, jsonOptions, typeCache) : node.Key);
333var value = attr.Value is JsonElement je
361JsonElement je => JsonSerializer.Deserialize<SerializedRenderFragment>(je.GetRawText(), jsonOptions),
368return attr.Value is JsonElement json ? ConvertTypedValue(json, attr.TypeAssembly!, attr.TypeName!, jsonOptions, typeCache) : attr.Value;
372private static object? ConvertTypedValue(JsonElement json, string assemblyName, string typeName, JsonSerializerOptions? jsonOptions, ComponentParametersTypeCache typeCache)
Microsoft.AspNetCore.Components.WebAssembly.Authentication (13)
Microsoft.AspNetCore.Components.WebAssembly.Server (12)
Microsoft.AspNetCore.Components.WebView (6)
IpcCommon.cs (6)
19public static bool TryDeserializeIncoming(string message, out IncomingMessageType messageType, out ArraySegment<JsonElement> args)
22public static bool TryDeserializeOutgoing(string message, out OutgoingMessageType messageType, out ArraySegment<JsonElement> args)
37private static bool TryDeserialize<T>(string message, out T messageType, out ArraySegment<JsonElement> args)
44var parsed = (JsonElement[])JsonSerializer.Deserialize(messageAfterPrefix, typeof(JsonElement[]), JsonSerializerOptionsProvider.Options);
46args = new ArraySegment<JsonElement>(parsed, 1, parsed.Length - 1);
Microsoft.AspNetCore.Grpc.JsonTranscoding (2)
Microsoft.AspNetCore.Http.Extensions (10)
Microsoft.AspNetCore.Identity (44)
Generated\361d1da7f942c932\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\361d1da7f942c932\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);
Microsoft.AspNetCore.JsonPatch.SystemTextJson (7)
Microsoft.AspNetCore.Mvc.ViewFeatures (6)
Microsoft.Build (3)
Microsoft.CodeAnalysis.Features (1)
Microsoft.CodeAnalysis.Workspaces.MSBuild (2)
Microsoft.CodeAnalysis.Workspaces.MSBuild.Contracts (2)
Microsoft.Deployment.DotNet.Releases (34)
Microsoft.DotNet.Arcade.Sdk (3)
Microsoft.DotNet.ProjectTools (6)
Microsoft.Extensions.AI (10)
Microsoft.Extensions.AI.Abstractions (50)
Functions\AIFunctionFactory.cs (24)
96/// invocation directly if the object is already of a compatible type. Otherwise, if the argument is a <see cref="JsonElement"/>, <see cref="JsonDocument"/>,
108/// By default, return values are serialized to <see cref="JsonElement"/> using <paramref name="options"/>'s
177/// invocation directly if the object is already of a compatible type. Otherwise, if the argument is a <see cref="JsonElement"/>, <see cref="JsonDocument"/>,
189/// Return values are serialized to <see cref="JsonElement"/> using <paramref name="serializerOptions"/> if provided,
267/// invocation directly if the object is already of a compatible type. Otherwise, if the argument is a <see cref="JsonElement"/>, <see cref="JsonDocument"/>,
279/// By default, return values are serialized to <see cref="JsonElement"/> using <paramref name="options"/>'s
356/// invocation directly if the object is already of a compatible type. Otherwise, if the argument is a <see cref="JsonElement"/>, <see cref="JsonDocument"/>,
368/// Return values are serialized to <see cref="JsonElement"/> using <paramref name="serializerOptions"/> if provided,
415/// Return values are serialized to <see cref="JsonElement"/> using <paramref name="options"/>'s
418/// <see cref="AIFunctionFactoryOptions.SerializerOptions"/>. If the argument is a <see cref="JsonElement"/>,
459/// invocation directly if the object is already of a compatible type. Otherwise, if the argument is a <see cref="JsonElement"/>, <see cref="JsonDocument"/>,
471/// By default, return values are serialized to <see cref="JsonElement"/> using <paramref name="options"/>'s
513JsonElement jsonSchema,
514JsonElement? returnJsonSchema = null) =>
522string name, string description, JsonElement jsonSchema, JsonElement? returnJsonSchema) :
527public override JsonElement JsonSchema => jsonSchema;
528public override JsonElement? ReturnJsonSchema => returnJsonSchema;
604public override JsonElement JsonSchema => FunctionDescriptor.JsonSchema;
605public override JsonElement? ReturnJsonSchema => FunctionDescriptor.ReturnJsonSchema;
850public JsonElement JsonSchema { get; }
851public JsonElement? ReturnJsonSchema { get; }
973JsonElement element => JsonSerializer.Deserialize(element, typeInfo),
1201return JsonElement.ParseValue(ref reader);
Microsoft.Extensions.AI.Abstractions.Tests (119)
Utilities\AIJsonUtilitiesTests.cs (77)
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));
570JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method);
573Assert.True(schema.TryGetProperty("title", out JsonElement titleElement));
595JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method, title: "override_title");
598Assert.True(doc.RootElement.TryGetProperty("title", out JsonElement titleElement));
611JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method);
613JsonElement properties = schema.GetProperty("properties");
662JsonElement schema = AIJsonUtilities.CreateJsonSchema(typeof(object));
681JsonElement schema = AIJsonUtilities.CreateJsonSchema(testData.Type, serializerOptions: options, inferenceOptions: createOptions);
706JsonElement schema = AIJsonUtilities.CreateJsonSchema(typeof(AIContent), serializerOptions: options);
716JsonElement expectedSchema = JsonDocument.Parse("""
723JsonElement schema = AIJsonUtilities.CreateJsonSchema(typeof(MyEnumValue?), serializerOptions: JsonContext.Default.Options);
1205JsonElement expectedSchema = JsonDocument.Parse("""
1218JsonElement actualSchema = AIJsonUtilities.CreateJsonSchema(typeof(ClassWithNullableMaxLengthProperty), serializerOptions: JsonContext.Default.Options);
1514JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method.Method, inferenceOptions: new()
1542JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method.Method, inferenceOptions: new()
1547JsonElement properties = schema.GetProperty("properties");
1559JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method.Method, inferenceOptions: new()
1569JsonElement properties = schema.GetProperty("properties");
1583JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method.Method, inferenceOptions: new()
1588JsonElement properties = schema.GetProperty("properties");
1602JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method.Method, inferenceOptions: new()
1607JsonElement properties = schema.GetProperty("properties");
1620JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method.Method, inferenceOptions: new()
1629JsonElement properties = schema.GetProperty("properties");
1638JsonElement schema = JsonDocument.Parse("""
1649JsonElement expectedSchema = JsonDocument.Parse("""
1665JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options);
1672JsonElement schema = JsonDocument.Parse("""
1683JsonElement expectedSchema = JsonDocument.Parse("""
1699JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options);
1706JsonElement schema = JsonDocument.Parse("""
1717JsonElement expectedSchema = JsonDocument.Parse("""
1734JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options);
1741JsonElement schema = JsonDocument.Parse("""
1753JsonElement expectedSchema = JsonDocument.Parse("""
1771JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options);
1778JsonElement schema = JsonDocument.Parse("""
1786JsonElement expectedSchema = JsonDocument.Parse("""
1798JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options);
1817JsonElement schema = AIJsonUtilities.CreateJsonSchema(testData.Type, serializerOptions: options, inferenceOptions: createOptions);
1835JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, transformOptions);
1869JsonElement schema = JsonDocument.Parse("{}").RootElement;
1882JsonElement schema = JsonDocument.Parse(invalidSchema).RootElement;
1894JsonElement schema = JsonDocument.Parse(booleanSchema).RootElement;
1898JsonElement result = AIJsonUtilities.TransformSchema(schema, transformOptions);
1910Assert.True(result.TryGetProperty("not", out JsonElement notValue));
1940[JsonSerializable(typeof(JsonElement))]
1952private static bool DeepEquals(JsonElement element1, JsonElement element2)
1954return JsonElement.DeepEquals(element1, element2);
1957private static void AssertDeepEquals(JsonElement element1, JsonElement element2)
Microsoft.Extensions.AI.Evaluation.Reporting.Tests (3)
Microsoft.Extensions.AI.Evaluation.Safety (4)
Microsoft.Extensions.AI.Integration.Tests (7)
Microsoft.Extensions.AI.OpenAI (14)
Microsoft.Extensions.AI.OpenAI.Tests (44)
OpenAIConversionTests.cs (22)
111var schema = JsonDocument.Parse("""
131var root = parsedParams.RootElement;
132Assert.True(root.TryGetProperty("additionalProperties", out var ap), "additionalProperties should be preserved");
141var jsonSchema = JsonDocument.Parse("""
172var root = parsedParams.RootElement;
174Assert.True(root.TryGetProperty("$defs", out var defs), "The $defs property should be preserved in the function parameters");
175Assert.True(defs.TryGetProperty("Person", out var person), "The Person definition should exist in $defs");
176Assert.True(person.TryGetProperty("properties", out var properties), "Person should have properties");
202var schema = JsonDocument.Parse("""
223var root = parsedParams.RootElement;
224Assert.True(root.TryGetProperty("additionalProperties", out var ap), "additionalProperties should be preserved");
708var root = jsonDoc.RootElement;
711Assert.True(root.TryGetProperty("properties", out var properties));
712Assert.True(properties.TryGetProperty("name", out var nameProperty));
772Assert.True(JsonElement.DeepEquals(JsonSerializer.SerializeToElement(new Dictionary<string, object?>
776}), JsonElement.Parse(tc.FunctionArguments.ToMemory().Span)));
828Assert.True(JsonElement.DeepEquals(JsonSerializer.SerializeToElement(new Dictionary<string, object?>
832}), JsonElement.Parse(m3.FunctionArguments.ToMemory().Span)));
1611Assert.Equal(42, ((JsonElement)deserializedArgs["number"]!).GetInt32());
1612Assert.True(((JsonElement)deserializedArgs["boolean"]!).GetBoolean());
1615var nestedObj = (JsonElement)deserializedArgs["nestedObject"]!;
OpenAIResponseClientTests.cs (16)
661JsonElement reasoningItem = secondRequest.RootElement.GetProperty("input").EnumerateArray()
662.Single(item => item.TryGetProperty("type", out var t) && t.GetString() == "reasoning");
1639Assert.Equal("dotnet/extensions", ((JsonElement)call.Arguments["repoName"]!).GetString());
1640Assert.Equal("What is the path to the README.md file for Microsoft.Extensions.AI.Abstractions?", ((JsonElement)call.Arguments["question"]!).GetString());
2016Assert.Equal("dotnet/extensions", ((JsonElement)firstCall.Arguments["repoName"]!).GetString());
2027Assert.Equal("dotnet/extensions", ((JsonElement)secondCall.Arguments["repoName"]!).GetString());
2028Assert.Equal("What is the path to the README.md file for Microsoft.Extensions.AI.Abstractions?", ((JsonElement)secondCall.Arguments["question"]!).GetString());
2427Assert.Equal("dotnet/extensions", ((JsonElement)firstCall.Arguments["repoName"]!).GetString());
2438Assert.Equal("dotnet/extensions", ((JsonElement)secondCall.Arguments["repoName"]!).GetString());
2439Assert.Equal("What is the path to the README.md file for Microsoft.Extensions.AI.Abstractions?", ((JsonElement)secondCall.Arguments["question"]!).GetString());
8889Assert.Equal("my-server", ((JsonElement)call.Arguments["resource_name"]!).GetString());
8890Assert.Equal("production", ((JsonElement)call.Arguments["env"]!).GetString());
8988Assert.Equal("my-server", ((JsonElement)call.Arguments["resource_name"]!).GetString());
8989Assert.Equal("production", ((JsonElement)call.Arguments["env"]!).GetString());
8996Assert.Equal("my-server", ((JsonElement)coalesced.Arguments["resource_name"]!).GetString());
8997Assert.Equal("production", ((JsonElement)coalesced.Arguments["env"]!).GetString());
Microsoft.Extensions.AI.Tests (53)
Functions\AIFunctionFactoryTest.cs (39)
162AIFunction func = AIFunctionFactory.Create((JsonElement param) => param, serializerOptions: options);
163JsonElement expectedResult = JsonDocument.Parse(jsonStringParam, new() { CommentHandling = JsonCommentHandling.Skip }).RootElement;
182AIFunction func = AIFunctionFactory.Create((JsonElement param) => param);
183JsonElement expectedResult = JsonDocument.Parse(JsonSerializer.Serialize(invalidJsonParam, JsonContext.Default.String)).RootElement;
366JsonElement expectedSchema = JsonDocument.Parse("""
473JsonElement valueParam = f.JsonSchema.GetProperty("properties").GetProperty("value");
545var result = (JsonElement?)await func.InvokeAsync(new()
577JsonElement schema = AIFunctionFactory.Create(method, target: null, options).JsonSchema;
579bool inRequired = schema.TryGetProperty("required", out JsonElement required) &&
581bool inProperties = schema.TryGetProperty("properties", out JsonElement properties) &&
582properties.TryGetProperty("service", out JsonElement _);
1234JsonElement expectedSchema = JsonDocument.Parse("""
1267JsonElement expectedSchema = JsonDocument.Parse("""
1304JsonElement schema = AIJsonUtilities.CreateJsonSchema(typeof(int), serializerOptions: AIJsonUtilities.DefaultOptions);
1556JsonElement schema = func.JsonSchema;
1557JsonElement properties = schema.GetProperty("properties");
1560JsonElement nullableIntSchema = properties.GetProperty("nullableInt");
1562nullableIntSchema.TryGetProperty("type", out JsonElement nullableIntType),
1569JsonElement nullableIntWithDefaultSchema = properties.GetProperty("nullableIntWithDefault");
1571nullableIntWithDefaultSchema.TryGetProperty("type", out JsonElement nullableIntWithDefaultType),
1577nullableIntWithDefaultSchema.TryGetProperty("default", out JsonElement nullableIntWithDefaultDefault),
1582JsonElement required = schema.GetProperty("required");
1596JsonElement schema = func.JsonSchema;
1597JsonElement properties = schema.GetProperty("properties");
1600JsonElement nullableStringSchema = properties.GetProperty("nullableString");
1602nullableStringSchema.TryGetProperty("type", out JsonElement nullableStringType),
1609JsonElement nullableIntSchema = properties.GetProperty("nullableInt");
1611nullableIntSchema.TryGetProperty("type", out JsonElement nullableIntType),
1618JsonElement nullableStringWithDefaultSchema = properties.GetProperty("nullableStringWithDefault");
1620nullableStringWithDefaultSchema.TryGetProperty("type", out JsonElement nullableStringWithDefaultType),
1626nullableStringWithDefaultSchema.TryGetProperty("default", out JsonElement nullableStringWithDefaultDefault),
1631JsonElement nullableIntWithDefaultSchema = properties.GetProperty("nullableIntWithDefault");
1633nullableIntWithDefaultSchema.TryGetProperty("type", out JsonElement nullableIntWithDefaultType),
1639nullableIntWithDefaultSchema.TryGetProperty("default", out JsonElement nullableIntWithDefaultDefault),
1644JsonElement required = schema.GetProperty("required");
1676JsonElement schema = func.JsonSchema;
1677JsonElement properties = schema.GetProperty("properties");
1683Assert.IsType<JsonElement>(result);
1684Assert.Equal(42, ((JsonElement)result!).GetInt32());
Microsoft.Extensions.Configuration.Json (4)
Microsoft.ML.GenAI.Phi (4)
Microsoft.ML.Tokenizers (79)
Model\SentencePieceTokenizer.cs (59)
574JsonElement root = doc.RootElement;
577if (!root.TryGetProperty("model", out JsonElement modelElement))
590if (modelElement.TryGetProperty("type", out JsonElement modelTypeElement) &&
603if (!modelElement.TryGetProperty("unk_id", out JsonElement unkIdElement))
618bool byteFallback = modelElement.TryGetProperty("byte_fallback", out JsonElement byteFallbackElement) &&
621if (!modelElement.TryGetProperty("vocab", out JsonElement vocabElement) ||
628foreach (JsonElement entry in vocabElement.EnumerateArray())
675if (root.TryGetProperty("normalizer", out JsonElement normalizerElement) &&
697if (root.TryGetProperty("pre_tokenizer", out JsonElement preTokenizerElement) &&
761private static Dictionary<string, int> ParseAddedTokens(JsonElement root)
764if (!root.TryGetProperty("added_tokens", out JsonElement addedTokens) || addedTokens.ValueKind != JsonValueKind.Array)
769foreach (JsonElement entry in addedTokens.EnumerateArray())
776if (!entry.TryGetProperty("special", out JsonElement specialElement) || specialElement.ValueKind != JsonValueKind.True)
781if (entry.TryGetProperty("content", out JsonElement contentElement) &&
782entry.TryGetProperty("id", out JsonElement idElement))
798JsonElement root,
807if (root.TryGetProperty("post_processor", out JsonElement postProcessor) &&
820JsonElement postProcessor,
845if (postProcessor.TryGetProperty("processors", out JsonElement processors) && processors.ValueKind == JsonValueKind.Array)
847foreach (JsonElement inner in processors.EnumerateArray())
865JsonElement postProcessor,
871if (!postProcessor.TryGetProperty("single", out JsonElement single) || single.ValueKind != JsonValueKind.Array)
876JsonElement? ppSpecialTokens = postProcessor.TryGetProperty("special_tokens", out JsonElement st) && st.ValueKind == JsonValueKind.Object
877? st : (JsonElement?)null;
880foreach (JsonElement item in single.EnumerateArray())
896else if (item.TryGetProperty("SpecialToken", out JsonElement specialToken) &&
897specialToken.TryGetProperty("id", out JsonElement idElement))
918JsonElement? ppSpecialTokens,
922if (ppSpecialTokens is JsonElement st &&
923st.TryGetProperty(tokenName, out JsonElement entry) &&
924entry.TryGetProperty("ids", out JsonElement ids) &&
962JsonElement postProcessor,
969if (postProcessor.TryGetProperty(property, out JsonElement el) && el.ValueKind == JsonValueKind.Array && el.GetArrayLength() >= 2 &&
1021private static string? GetStringOrNull(JsonElement element, string propertyName) =>
1022element.TryGetProperty(propertyName, out JsonElement value) && value.ValueKind == JsonValueKind.String
1026private static byte[]? ExtractPrecompiledCharsMap(JsonElement normalizer)
1036if (normalizer.TryGetProperty("precompiled_charsmap", out JsonElement mapElement) &&
1048normalizer.TryGetProperty("normalizers", out JsonElement normalizersElement) &&
1055foreach (JsonElement inner in normalizersElement.EnumerateArray())
1077private static bool NormalizerCollapsesWhitespace(JsonElement normalizer)
1089return !normalizer.TryGetProperty("strip_right", out JsonElement stripRight) || stripRight.ValueKind != JsonValueKind.False;
1098normalizer.TryGetProperty("normalizers", out JsonElement normalizersElement) &&
1101foreach (JsonElement inner in normalizersElement.EnumerateArray())
1114private static bool ReplaceCollapsesSpaces(JsonElement replace)
1116if (!replace.TryGetProperty("pattern", out JsonElement patternElement) ||
1118!patternElement.TryGetProperty("Regex", out JsonElement regexElement) ||
1147private static bool PreTokenizerSplitsWhitespace(JsonElement preTokenizer)
1162preTokenizer.TryGetProperty("pretokenizers", out JsonElement preTokenizersElement) &&
1165foreach (JsonElement inner in preTokenizersElement.EnumerateArray())
1181private static void ValidatePreTokenizer(JsonElement preTokenizer)
1198if (preTokenizer.TryGetProperty("pretokenizers", out JsonElement pretokenizers) &&
1201foreach (JsonElement inner in pretokenizers.EnumerateArray())
1213private static void ExtractMetaspaceSettings(JsonElement preTokenizer, ref bool addDummyPrefix, ref bool escapeWhiteSpaces)
1223if (preTokenizer.TryGetProperty("add_prefix_space", out JsonElement addPrefixElement))
1233if (preTokenizer.TryGetProperty("replacement", out JsonElement replacementElement))
1252if (preTokenizer.TryGetProperty("prepend_scheme", out JsonElement prependSchemeElement))
1263preTokenizer.TryGetProperty("pretokenizers", out JsonElement preTokenizersElement) &&
1266foreach (JsonElement inner in preTokenizersElement.EnumerateArray())
Normalizer\SentencePieceNormalizationStep.cs (20)
83public static bool HasRichSteps(JsonElement normalizer)
85if (normalizer.ValueKind != JsonValueKind.Object || !normalizer.TryGetProperty("type", out JsonElement typeElement) ||
95if (normalizer.TryGetProperty("normalizers", out JsonElement steps) && steps.ValueKind == JsonValueKind.Array)
97foreach (JsonElement step in steps.EnumerateArray())
127public static SentencePieceNormalizationStep Build(JsonElement normalizer)
134string? type = normalizer.TryGetProperty("type", out JsonElement typeElement) && typeElement.ValueKind == JsonValueKind.String
140if (normalizer.TryGetProperty("normalizers", out JsonElement steps) && steps.ValueKind == JsonValueKind.Array)
142foreach (JsonElement step in steps.EnumerateArray())
152if (normalizer.TryGetProperty("precompiled_charsmap", out JsonElement mapElement))
170stripLeft: !normalizer.TryGetProperty("strip_left", out JsonElement left) || left.ValueKind != JsonValueKind.False,
171stripRight: !normalizer.TryGetProperty("strip_right", out JsonElement right) || right.ValueKind != JsonValueKind.False);
190if (normalizer.TryGetProperty("prepend", out JsonElement prependElement) &&
224private static bool ReplaceIsWhitespaceCollapse(JsonElement replace)
226if (!replace.TryGetProperty("pattern", out JsonElement patternElement) ||
228!patternElement.TryGetProperty("Regex", out JsonElement regexElement) ||
415public static ReplaceStep Create(JsonElement normalizer)
417string content = normalizer.TryGetProperty("content", out JsonElement contentElement) && contentElement.ValueKind == JsonValueKind.String
419if (!normalizer.TryGetProperty("pattern", out JsonElement pattern) || pattern.ValueKind != JsonValueKind.Object)
424if (pattern.TryGetProperty("String", out JsonElement literal))
434if (pattern.TryGetProperty("Regex", out JsonElement regex))
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)
Microsoft.NET.Build.Containers (27)
LocalDaemons\ContainerRuntimes.cs (14)
82if (!config.RootElement.TryGetProperty("ServerErrors", out JsonElement errorProperty) ||
122JsonElement dockerInfo = GetDockerConfig().RootElement;
124dockerInfo.TryGetProperty("DockerRootDir", out JsonElement dockerRootDir) &&
127dockerInfo.TryGetProperty("host", out JsonElement host) &&
128host.TryGetProperty("buildahVersion", out JsonElement buildahVersion) &&
173JsonElement rootElement = GetDockerConfig().RootElement;
174if (rootElement.TryGetProperty("RegistryConfig", out JsonElement registryConfig) &&
176registryConfig.TryGetProperty("IndexConfigs", out JsonElement indexConfigs) &&
182property.Value.TryGetProperty("Secure", out JsonElement secure) &&
191if (rootElement.TryGetProperty("registries", out JsonElement registries) &&
197property.Value.TryGetProperty("Insecure", out JsonElement insecure) &&
217if (!GetDockerConfig().RootElement.TryGetProperty("DriverStatus", out JsonElement driverStatus) ||
223foreach (JsonElement item in driverStatus.EnumerateArray())
230JsonElement[] values = item.EnumerateArray().ToArray();
LocalDaemons\DockerCli.cs (13)
158if (!config.RootElement.TryGetProperty("ServerErrors", out JsonElement errorProperty))
241var rootElement = GetDockerConfig().RootElement;
244if (rootElement.TryGetProperty("RegistryConfig", out var registryConfig) && registryConfig.ValueKind == JsonValueKind.Object)
246if (registryConfig.TryGetProperty("IndexConfigs", out var indexConfigs) && indexConfigs.ValueKind == JsonValueKind.Object)
251&& property.Value.TryGetProperty("Secure", out var secure)
262if (rootElement.TryGetProperty("registries", out var registries) && registries.ValueKind == JsonValueKind.Object)
267&& property.Value.TryGetProperty("Insecure", out var insecure)
614var dockerinfo = GetDockerConfig().RootElement;
618dockerinfo.TryGetProperty("DockerRootDir", out var dockerRootDir) && dockerRootDir.GetString() is not null;
619var hasPodmanProperty = dockerinfo.TryGetProperty("host", out var host) && host.TryGetProperty("buildahVersion", out var buildahVersion) && buildahVersion.GetString() is not null;
633if (!GetDockerConfig().RootElement.TryGetProperty("DriverStatus", out var driverStatus) || driverStatus.ValueKind != JsonValueKind.Array)
638foreach (var item in driverStatus.EnumerateArray())
Microsoft.NET.HostModel (2)
Microsoft.SourceLink.Tools.Package (1)
Microsoft.TemplateEngine.Edge (1)
Microsoft.TemplateEngine.Orchestrator.RunnableProjects (1)
Microsoft.TemplateEngine.Utils (1)
Microsoft.TemplateSearch.Common (1)
Microsoft.TestPlatform.CommunicationUtilities (144)
Microsoft.TestPlatform.TestHostRuntimeProvider (3)
NuGet.Protocol (6)
RepoTasks (4)
rzc (5)
Shared.Tests (4)
System.Text.Json (210)
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\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());