json.lua

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

  • Owner: rxi/json.lua
  • Platform: Windows,Linux,Mac
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

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.

Main metrics

Overview
Name With Ownerrxi/json.lua
Primary LanguageLua
Program languageLua (Language Count: 2)
Platform
License:MIT License
所有者活动
Created At2015-08-12 19:18:12
Pushed At2023-11-28 04:38:13
Last Commit At2020-06-18 17:03:53
Release Count3
Last Release Namev0.1.2 (Posted on )
First Release Namev0.1.0 (Posted on )
用户参与
Stargazers Count2.1k
Watchers Count45
Fork Count376
Commits Count52
Has Issues Enabled
Issues Count32
Issue Open Count15
Pull Requests Count1
Pull Requests Open Count13
Pull Requests Close Count10
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private