Hello world. Here is my code:
import std/[json]
var
t = (a: "A", b: 5)
echo pretty %t
Here is what the compiler says:
t.nim(6, 13) Error: type mismatch: got <tuple[a: string, b: int]>
Please, how can create my json node ?
The source says
proc `%`*[T: object](o: T): JsonNode =
## Construct JsonNode from tuples and objects.
result = newJObject()
for k, v in o.fieldPairs: result[k] = %v
which implies this function should have have taken both objects and tuples.
To get around this you could declare your own function
proc `%`*[T: tuple](o: T): JsonNode =
result = newJObject()
for k, v in o.fieldPairs: result[k] = %v
You could open an issue on github. It should be a simple enough fix.
Still learning Nim.
Would this be acceptable?
import std/[json, jsonutils]
var
t = (a: "A", b: 5)
x = t.toJson
echo pretty(x)
echo type(x)