json.lua

Lua 的轻量级 JSON 库。「A lightweight JSON library for Lua」

Github星跟踪图

json.lua

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
  • 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.

主要指标

概览
名称与所有者rxi/json.lua
主编程语言Lua
编程语言Lua (语言数: 2)
平台
许可证MIT License
所有者活动
创建于2015-08-13 03:18:12
推送于2023-11-28 12:38:13
最后一次提交2020-06-19 00:03:53
发布数3
最新版本名称v0.1.2 (发布于 )
第一版名称v0.1.0 (发布于 )
用户参与
星数2.1k
关注者数43
派生数375
提交数52
已启用问题?
问题数32
打开的问题数15
拉请求数1
打开的拉请求数13
关闭的拉请求数10
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?