New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Support for System.Text.Json.JsonElement #527
Labels
Comments
I think it's ok to add a support for it only for This could be added also as a function to e.g Feel free to start a PR to see how it goes. |
r-Larch
added a commit
to r-Larch/scriban
that referenced
this issue
Feb 11, 2024
…ban#527 - Introduced JsonElementExtensions.cs to convert JsonElements into Scriban objects - Updated ScriptArray.cs and ScriptObject.cs to handle JsonElements - Enhanced ScriptObjectExtensions.cs with methods for importing JsonElements into script objects - Extended Template.cs with a Render method that accepts a JsonElement as input - Added new test cases to validate JSON support
r-Larch
added a commit
to r-Larch/scriban
that referenced
this issue
Feb 12, 2024
…ban#527 - Introduced JsonElementExtensions.cs to convert JsonElements into Scriban objects - Updated ScriptArray.cs and ScriptObject.cs to handle JsonElements - Enhanced ScriptObjectExtensions.cs with methods for importing JsonElements into script objects - Extended Template.cs with a Render method that accepts a JsonElement as input - Added new test cases to validate JSON support
r-Larch
added a commit
to r-Larch/scriban
that referenced
this issue
Feb 12, 2024
…criban#527 - Implemented FromJson function to convert JSON to Scriban value - Implemented ToJson function to convert Scriban value to JSON - Added new test cases for JSON parsing and conversion in TestObjectFunctions.cs
r-Larch
added a commit
to r-Larch/scriban
that referenced
this issue
Feb 12, 2024
…ban#527 - Introduced JsonElementExtensions.cs to convert JsonElements into Scriban objects - Updated ScriptArray.cs and ScriptObject.cs to handle JsonElements - Enhanced ScriptObjectExtensions.cs with methods for importing JsonElements into script objects - Extended Template.cs with a Render method that accepts a JsonElement as input - Added new test cases to validate JSON support
r-Larch
added a commit
to r-Larch/scriban
that referenced
this issue
Feb 12, 2024
…criban#527 - Implemented FromJson function to convert JSON to Scriban value - Implemented ToJson function to convert Scriban value to JSON - Added new test cases for JSON parsing and conversion in TestObjectFunctions.cs
r-Larch
added a commit
to r-Larch/scriban
that referenced
this issue
Feb 12, 2024
…ban#527 - Introduced JsonElementExtensions.cs to convert JsonElements into Scriban objects - Updated ScriptArray.cs and ScriptObject.cs to handle JsonElements - Enhanced ScriptObjectExtensions.cs with methods for importing JsonElements into script objects - Extended Template.cs with a Render method that accepts a JsonElement as input - Added new test cases to validate JSON support
r-Larch
added a commit
to r-Larch/scriban
that referenced
this issue
Feb 12, 2024
…criban#527 - Implemented FromJson function to convert JSON to Scriban value - Implemented ToJson function to convert Scriban value to JSON - Added new test cases for JSON parsing and conversion in TestObjectFunctions.cs
r-Larch
added a commit
to r-Larch/scriban
that referenced
this issue
Feb 12, 2024
…ban#527 - Introduced JsonElementExtensions.cs to convert JsonElements into Scriban objects - Updated ScriptArray.cs and ScriptObject.cs to handle JsonElements - Enhanced ScriptObjectExtensions.cs with methods for importing JsonElements into script objects - Extended Template.cs with a Render method that accepts a JsonElement as input - Added new test cases to validate JSON support
r-Larch
added a commit
to r-Larch/scriban
that referenced
this issue
Feb 12, 2024
…criban#527 - Implemented FromJson function to convert JSON to Scriban value - Implemented ToJson function to convert Scriban value to JSON - Added new test cases for JSON parsing and conversion in TestObjectFunctions.cs
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Current behavior
Wenn using
System.Text.Json
deserializing toDictionary<string, object>
does not work, because it producesDictionary<string, JsonElement>
andJsonElement
can not be added directly toScriptObject
because JsonElementhas no public properties to be exposed in the scriban runtine.
See the following Example to understand how scriban handles JsonElement:
Expected behavior
It should be possible to add
JsonElement
to aScriptObject
orScriptArray
while exposing the actual JSON fields to the runtime.Motivation for Change
I think providing first class support for .NET build-in JSON types makes scriban a even more powerful engine.
How I solved it
To solve the problem I wrote a extension method for ScriptObject where I loop through the JsonElement and add all elements to a ScriptObject or ScriptArray.
Working Example:
API Proposal
Pull-Request?
I would provide a pull request.
The text was updated successfully, but these errors were encountered: