Hi folks, I'm a beginner here, so sorry for the dumb questions and thanks in advance for the patience.
I'm writing a script that builds a json and writes it to a file. It all works except for any nested [Str:Obj?] objects are not handled properly by the json writer. Is there something special I need to do?
james g Wed 20 Nov 2024
Hi folks, I'm a beginner here, so sorry for the dumb questions and thanks in advance for the patience.
I'm writing a script that builds a json and writes it to a file. It all works except for any nested [Str:Obj?] objects are not handled properly by the json writer. Is there something special I need to do?
What I have is essentially
[ [ "name":"foo", "type":"class", "methods":[ [ "name":"bar", "type":"method" ], [ "name":"bar", "type":"method" ] ], ]Any top level objects are handled correctly (class in this case), but none of the nested methods are.
I'm using the following to write the file
myObj:= ... json:= util::JsonOutStream(File("myFile.json".toUri)) json.writeJson(myObj).closematthew Thu 21 Nov 2024
I tried to reproduce using this Fantom script:
using util @Js class Main { static Void main(Str[] args) { // echo(Person("Matthew", "Giannini")) m := [ [ "name":"foo", "type":"class", "methods":[ [ "name":"bar", "type":"method" ], [ "name":"bar", "type":"method" ] ], ] ] echo(JsonOutStream.writeJsonToStr(m)) } }And i get this output which looks correct.
[{"methods":[{"name":"bar","type":"method"},{"name":"bar","type":"method"}],"name":"foo","type":"class"}]james g Fri 22 Nov 2024
Ahhhh.... * sigh * . What could it be but a dumb beginner error. :D
Either way, thanks! You got me there. Before it got to the final stream, I had a little code gremlin casting it to a string.