Json.lua
A lightweight JSON library for Lua
Install / Use
/learn @rxi/Json.luaREADME
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 280sloc, 9kb
- 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
- Trying to encode values which are unrepresentable in JSON will never result in type conversion or other magic: sparse arrays, tables with mixed key types or invalid numbers (NaN, -inf, inf) will raise an error
nullvalues contained within an array or object are converted toniland 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.
Related Skills
node-connect
342.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
342.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.7kCommit, push, and open a PR

