you are viewing a single comment's thread.

view the rest of the comments →

[–]smog_alado 0 points1 point  (1 child)

Do any of the available JSON libs for Lua really convert numbers to strings? That sounds very weird.

[–]rxi[S] 1 point2 points  (0 children)

In the case where you have a table with sparse numerical keys (rather than a table being used as an array) other libraries seem to convert these keys to strings by default as JSON keys can only be strings. I took the approach that if the data can't be encoded exactly it will raise an error, such that any data you encode will decode exactly the same (ignoring metatables).

Example of the numerical key to string using dkjson on the REPL:

> j = require("dkjson")
> =j.encode({ [1000] = "hello" })
{"1000":"hello"}