forked from Dependencies/lua-json
9beca8a5bd
Using Lua5.3, tonumber() will represent the float `1` as "1.0" instead of "1". Using string.format("%14g, x) `1` is converted to "1" regardless of whether it's an int or float. All other conversions seem to be uneffected. |
||
---|---|---|
bench | ||
test | ||
LICENSE | ||
README.md | ||
json.lua |
README.md
A lightweight JSON library for Lua
Features
- Implemented in pure Lua: works with 5.1, 5.2, 5.3 and JIT
- Fast: generally outperforms other pure Lua JSON implementations (benchmark scripts)
- Tiny: around 270sloc, 8kb
- Proper error messages, eg:
expected '}' or ',' at line 203 col 30
Usage
The json.lua file should be dropped into an existing project and required by it:
json = require "json"
The library provides the following functions:
json.encode(value)
Returns a string representing value
encoded in JSON.
json.encode({ 1, 2, 3, { x = 10 } }) -- Returns '[1,2,3,{"x":10}]'
json.decode(str)
Returns a value representing the decoded JSON string.
json.decode('[1,2,3,{"x":10}]') -- Returns { 1, 2, 3, { x = 10 } }
Notes
- Tables with the key
1
set are treated as arrays when encoding null
values contained within an array or object are converted tonil
and are therefore lost upon decoding- Pretty encoding is not supported,
json.encode()
only encodes to a compact format
License
This library is free software; you can redistribute it and/or modify it under the terms of the MIT license. See LICENSE for details.