Array functions for JSON arrays #1733
-
Version used Describe the bug
To Reproduce Sample Codevoid Main()
{
var expression = "participants.find(p => p.id)";
string d = File.ReadAllText(@"<PATH_TO_JSON>\MinimumReproducible.json");
JObject jObject = JObject.Parse(d);
var eval = new Engine()
.SetValue("log", new Action<object>(Console.WriteLine))
.SetValue("participants", jObject["participants"])
.Execute($"let result = {expression}; log(result)")
.Evaluate("result");
} Sample JSON{
"participants": [
{
"participantType": {
"id": 1,
"name": "Client"
},
"id": "8d1d2e485aab4c52be5c5926353fb9db"
},
{
"participantType": {
"id": 4,
"name": "Vendor"
},
"id": "9b68c253d55749ee89a4c993d13e5bc3"
},
{
"participantType": {
"id": 1,
"name": "Client"
},
"id": "a8f6ab053b9944edb5a5982c897c70e1"
}
]
} Expected behavior Additional context |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You need to configure your engine to allow specific types to get array prototype, see https://github.com/sebastienros/jint/blob/main/Jint.Tests/Runtime/InteropTests.SystemTextJson.cs for an example, you don't need to set |
Beta Was this translation helpful? Give feedback.
You need to configure your engine to allow specific types to get array prototype, see https://github.com/sebastienros/jint/blob/main/Jint.Tests/Runtime/InteropTests.SystemTextJson.cs for an example, you don't need to set
TypeResolver
with Newtonsoft.JSON, it's an STJ workaround.