mirror of
https://github.com/status-im/nim-json-serialization.git
synced 2025-02-21 06:18:09 +00:00
Read keys of table as string as this is only valid json, but convert them if needed
This commit is contained in:
parent
cb695d175f
commit
193d103934
@ -7,13 +7,27 @@ type
|
|||||||
proc writeValue*(writer: var JsonWriter, value: TableType) =
|
proc writeValue*(writer: var JsonWriter, value: TableType) =
|
||||||
writer.beginRecord()
|
writer.beginRecord()
|
||||||
for key, val in value:
|
for key, val in value:
|
||||||
writer.writeField key, val
|
writer.writeField $key, val
|
||||||
writer.endRecord()
|
writer.endRecord()
|
||||||
|
|
||||||
|
|
||||||
|
template to*(a: string, b: typed): untyped =
|
||||||
|
{.error: "doesnt support keys with type " & $type(b) .}
|
||||||
|
|
||||||
|
template to*(a: string, b: type int): int =
|
||||||
|
parseInt(a)
|
||||||
|
|
||||||
|
template to*(a: string, b: type float): float =
|
||||||
|
parseFloat(a)
|
||||||
|
|
||||||
|
template to*(a: string, b: type string): string =
|
||||||
|
a
|
||||||
|
|
||||||
|
|
||||||
proc readValue*(reader: var JsonReader, value: var TableType) =
|
proc readValue*(reader: var JsonReader, value: var TableType) =
|
||||||
type KeyType = type(value.keys)
|
type KeyType = type(value.keys)
|
||||||
type ValueType = type(value.values)
|
type ValueType = type(value.values)
|
||||||
value = init TableType
|
value = init TableType
|
||||||
for key, val in readObject(reader, KeyType, ValueType):
|
for key, val in readObject(reader, string, ValueType):
|
||||||
value[key] = val
|
value[to(key, KeyType)] = val
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user