Describe the feature
The Document class in AWS.Runtime is a simple JSON model class that is used to e.g. pass the JSON schema and response for AWS bedrock tool use.
.NET natively supports JsonNode and JsonDocument/JsonElement for working with JSON. Currently it is difficult to interoperate with these classes:
Document.FromObject only supports JsonElement -- for JsonNode you need to do `Document.FromObject(JsonDocument.Parse(node.ToJsonString()).RootElement);
- There is no way to convert from a
Document to a JsonNode or JsonElement.
Use Case
I have a JsonNode object that defines the JSON schema (via GetJsonSchemaAsNode) that I want to use to specify an AWS Bedrock tool as using (setting the Json property of the ToolSpecification). I also want to use that JSON schema object to deserialize the JSON back into a .NET class. I'm using JsonNode because I need it to work with other parts of the project.
Proposed Solution
I propose for Document.FromObject:
- A
Document.FromObject(JsonDocument doc) overload that evaluates to Document.FromObject(doc.RootElement);
- A
Document.FromObject(JsonNode node) overload that evaluates to Document.FromObject(JsonDocument.Parse(node.ToJsonString())) or equivalent.
I also propose the following converters to convert to the corresponding .NET types:
JsonDocument Document.AsJsonDocument();
JsonElement Document.AsJsonElement();
JsonNode Document.AsJsonNode().
Other Information
No response
Acknowledgements
AWS .NET SDK and/or Package version used
AWS.BedrockRuntime 4.0.1.1
Targeted .NET Platform
.NET 8
Operating System and version
Windows 11
Describe the feature
The
Documentclass in AWS.Runtime is a simple JSON model class that is used to e.g. pass the JSON schema and response for AWS bedrock tool use..NET natively supports
JsonNodeandJsonDocument/JsonElementfor working with JSON. Currently it is difficult to interoperate with these classes:Document.FromObjectonly supportsJsonElement-- forJsonNodeyou need to do `Document.FromObject(JsonDocument.Parse(node.ToJsonString()).RootElement);Documentto aJsonNodeorJsonElement.Use Case
I have a
JsonNodeobject that defines the JSON schema (viaGetJsonSchemaAsNode) that I want to use to specify an AWS Bedrock tool as using (setting theJsonproperty of theToolSpecification). I also want to use that JSON schema object to deserialize the JSON back into a .NET class. I'm usingJsonNodebecause I need it to work with other parts of the project.Proposed Solution
I propose for
Document.FromObject:Document.FromObject(JsonDocument doc)overload that evaluates toDocument.FromObject(doc.RootElement);Document.FromObject(JsonNode node)overload that evaluates toDocument.FromObject(JsonDocument.Parse(node.ToJsonString()))or equivalent.I also propose the following converters to convert to the corresponding .NET types:
JsonDocument Document.AsJsonDocument();JsonElement Document.AsJsonElement();JsonNode Document.AsJsonNode().Other Information
No response
Acknowledgements
AWS .NET SDK and/or Package version used
AWS.BedrockRuntime 4.0.1.1
Targeted .NET Platform
.NET 8
Operating System and version
Windows 11