1
0
Fork 0
A lightweight JSON library for Lua
 
 
Go to file
rxi 9720bb9f10 Added warmup for JIT in benchmark scripts 2015-08-14 19:21:42 +01:00
bench Added warmup for JIT in benchmark scripts 2015-08-14 19:21:42 +01:00
test Added more parts to the "strict decode" test 2015-08-13 18:37:57 +01:00
LICENSE Initial commit 2015-08-11 21:08:33 +01:00
README.md Changed project overview text in README 2015-08-13 18:40:09 +01:00
json.lua Removed support for numbers starting with "." 2015-08-13 18:33:18 +01:00

README.md

json.lua

A lightweight JSON library for Lua

Features

  • Pure Lua implementation
  • 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 to nil 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.