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?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?