In the image above is example of the result of using ToJson with my current XNode Tree, I would like the year to be presented as an integer, that is, without the “quote” marks.
Other than editing the string after the fact which will have thousands of entries eventually, is there a way to set the vaule type ahead of time?
Encountered this issue as well, and I don’t think that’s possible using the default XML nodes. Maybe using Newtonsoft.JSON helps there?
edit: just saw that on SO
edit2: also, looking at the .net6 documentation on JSON serialization, it looks like it’s able to serialize JSON with something else than strings. not sure how that’ll apply to the 2022 branch tho.
Not quite sure, but I think you have to either add a datatype attribute to your elements or define a XML schema that assigns the datatypes to the elements. Ofc this will only work if the parser used by ToJSON supports that. Further Info.
that’s what I had in mind yeah, did something similar when needed to enforce JSON arrays on serialized output. guess there should be a similar XML attribute that newtonsoft “understands” and converts to the type you want.
It looks like the generated C# can only rely on System.Text.JSON which only seems to be available in >= net5.0, hence not compatible with the .4 branch of vvvv.
edit : maybe other JSON to C# things would do the trick, let’s see…
edit2: ok now I’m super confused : internally JSONReader (Generic) indeed uses System.Text.Json.dll, the nuget page shows it’s compatible with netstandard2.0, but Microsoft’s documentation tells that " The requested page is not available for .NET Standard 2.0. You have been redirected to the newest product version this page is available for." and redirects me to the net6.0…
edit3: ok, looks like one explicitely has to install System.Text.JSON inside Visual Studio for it to work. jesus that .net ecosystem is soooo confusing… managed to build a dll in the end, yuhu!
yep, was more confused about VS not able to load System.Text.JSON out of the box and the MS documentation telling that this does not exist in netstandard2.0… doh.
edit: works like a charm. small add though : if one wants to generate a working JSON schema from some existing JSON, they’d have to use jtd-infer.