mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 22:02:27 +00:00
Further improve JSON serialization
This commit is contained in:
parent
4814b6bdf8
commit
6ee18986e4
20 changed files with 868 additions and 687 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue