OK, so I have a custom object type, which I'm able to convert fine to a JsonNode.
Now, I have a function that returns something to javascript.
How do I transform this JsonNode into something that can be handled as a JavaScript value? (I guess JsObject from jsffi, but I'm not sure how to wrap it)
Not that it can be of general use, but this is what I ended up with:
when defined(WEB):
proc generateJsObject*(n: Value): JsObject =
case n.kind
of Null : result = toJs(nil)
of Boolean : result = toJs(n.b)
of Integer : result = toJs(n.i)
of Floating : result = toJs(n.f)
of Version : result = toJs($(n))
of Type : result = toJs($(n.t))
of Char : result = toJs($(n.c))
of String,
Word,
Literal,
Label : result = toJs(n.s)
of Attribute,
AttributeLabel: result = toJs(n.r)
of Path,
PathLabel :
result = newJsObject()
for i,v in n.p:
result[i] = generateJsObject(v)
of Symbol : result = toJs($(n.m))
of Date : discard
of Binary : discard
of Inline,
Block :
var ret: seq[JsObject] = @[]
for i,v in n.a:
ret.add(generateJsObject(v))
result = toJs(ret)
of Dictionary :
result = newJsObject()
for k,v in pairs(n.d):
result[k] = generateJsObject(v)
of Function,
Database,
Bytecode,
Nothing,
Any : discard