Static types, by definition, have to be known at compile time, so there is not much you can do for that.
What you **can** do is mimic what dynamic languages do and write a wrapper type using [object variants](https://nim-lang.org/docs/manual.html#types-object-variants). You can see an example for json [here](https://github.com/nim-lang/Nim/blob/master/lib/pure/json.nim#L561-L587)