aws / aws/aws-sdk-net

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

Open
#3,915 5 comments 0 reactions 0 assignees View on GitHub
feature-request p2 queued
Dominant language
C#
Stars
140
Forks
891
Avg merge
21h 51m
Merged PRs (30d)
10

Description

### 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

- [x] 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

Contributor guide

Open the contributing guide

Research direction

Locate the AWS.Runtime Document class and its existing FromObject(JsonElement) entry point. Compare the requested JsonDocument and JsonNode overloads with the proposed AsJsonDocument, AsJsonElement, and AsJsonNode conversions, then verify that the .NET 8 interop paths remove the caller's current parsing workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend-api-design
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.