Using json filter on a JObject coverts all values to string
Closed this issue · 2 comments
atthevergeof commented
When passing a JObject as the context and using the json
filter in the template, all the values, regardless of the original datatype, are getting converted to string in the output.
For example, consider the following program:
using Fluid;
using Newtonsoft.Json.Linq;
var parser = new FluidParser();
var template = parser.Parse("{{ root | json: true }}");
var contextObj = new JObject
{
["root"] = new JObject
{
["a"] = true,
["b"] = 1,
["c"] = DateTime.Now,
["d"] = "string",
["e"] = null,
["f"] = new JObject
{
["f_a"] = 1.2
},
["g"] = new JArray
{
"val1", "val2"
}
}
};
var context = new TemplateContext(contextObj);
var output = template.Render(context);
Console.WriteLine(output);
The output of the program is:
{
"a": "True",
"b": "1",
"c": "12/08/2023 20:00:38",
"d": "string",
"e": "",
"f": {
"f_a": "1.2"
},
"g": [
"val1",
"val2"
]
}
All the basic datatypes are getting converted to string, which is not correct.
The expected output of the program is:
{
"a": true,
"b": 1,
"c": "12/08/2023 20:00:38", // Not sure what is the ideal way to print date time objects
"d": "string",
"e": null,
"f": {
"f_a": 1.2
},
"g": [
"val1",
"val2"
]
}
drosenba commented
When does NuGet package get updated? In NuGet I see "last updated 5 months ago Latest version: 2.5.0". The commit for this issue was in Dec.
sebastienros commented