Skip to content

Support interop with JsonNode and JsonElement when working with AWS.Runtime Documents #3915

@rhdunn

Description

@rhdunn

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

  • I may be able to implement this feature request
  • This feature might incur a breaking change

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestA feature should be added or improved.p2This is a standard priority issuequeued

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions