Further improve JSON serialization

This commit is contained in:
Justine Tunney 2022-07-11 23:06:49 -07:00
parent 4814b6bdf8
commit 6ee18986e4
20 changed files with 868 additions and 687 deletions

View file

@ -61,6 +61,8 @@ assert(EncodeJson(0) == "0")
assert(EncodeJson(3.14) == "3.14")
assert(EncodeJson({2, 1}) == "[2,1]")
assert(EncodeLua(" [\"new\nline\"] ") == "\" [\\\"new\\nline\\\"] \"")
-- EncodeLua() permits serialization of cyclic data structures
x = {2, 1}
x[3] = x
@ -78,7 +80,13 @@ x = {2, 1}
x[3] = x
json, err = EncodeJson(x)
assert(not json)
assert(err == "serialization failed")
assert(err == "won't serialize cyclic lua table")
-- pass the parser to itself lool
json, err = EncodeJson(EncodeJson)
assert(not json)
print(err)
assert(err == "unsupported lua type")
-- EncodeJson() sorts table entries
-- JSON always requires quotes around key names