lua-pretty-json
Pretty json serializer and parser for lua.
$ opm get xiedacon/lua-pretty-json
lua-pretty-json
[!MIT](https://github.com/xiedacon/lua-pretty-json/blob/master/LICENSE)
Usage
local json = require "pretty.json"
local str = json.stringify({
"aa\"\a\v", "ccc", true, false,
{
a = "a",
b = "a",
"aaa", "ccc", "ddd",
}
}, nil, 4)
print(str)
-- [
-- "aa\"\u0007\u000b",
-- "ccc",
-- true,
-- false,
-- {
-- "1": "aaa",
-- "2": "ccc",
-- "3": "ddd",
-- "a": "a",
-- "b": "a"
-- }
-- ]
json.parse(str)
API
json.stringify(obj, replacer, space, print_address)
obj<any>需要序列化的值replacer<function>同 js JSON.stringifyspace<number>空格数print_address<boolean>输出内存地址
json.parse(str, without_null)
str<string>需要反序列化的值without_null<boolean>是否输出 null 值,默认使用json.null
json.null
License
Copyright (c) 2018 xiedacon
Authors
xiedacon
License
mit
Versions
-
Pretty json serializer and parser for lua. 2019-02-12 09:28:48