Giter Club home page Giter Club logo

qjson.lua's Introduction

Tiny, quick JSON encoding/decoding in pure Lua.

Release Shield License Linter Badge github/Vurv78

Features

  • Pure lua, should work on every version (5.1-5.4, JIT)
  • Quick, focused on performance. (See benchmarks below)
  • Very small, ~180 sloc.
  • Decent error handling: Expected : to follow key for object at char 39

Usage

local json = require "qjson"
print(json.encode {
	hello = "world!",
	qjson = { "fast", "simple", "tiny" }
})

--[[
	{"qjson":["fast","simple","tiny"],"hello":"world!"}
]]

print(json.decode([[
	{ "foo": "bar" }
]]))

Notes

  • null is output as a special table instance, retrieved from qjson.NULL
  • This does not guarantee 100% compatibility with the more niche parts of the JSON spec (like unicode escapes)

Benchmarks

Using benchmarks/bench.lua (which tests the simdjson twitter example) through WSL:

LuaJIT 2.1.0-beta3 (Windows 11)
11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
Name (Decode) Min Max Avg Avg / Best
rxi/json 0.005 0.009 0.00672 x1
actboy168/json 0.011 0.016 0.01295 x1.92708
luadist/dkjson 0.012 0.017 0.01426 x2.12202
vurv78/qjson 0.008 0.015 0.00939 x1.39732
grafi-tt/lunajson 0.005 0.012 0.007095 x1.0558
Name (Encode) Min Max Avg Avg / Best
rxi/json 0.01 0.02 0.011745 x7.93581
actboy168/json 0.009 0.014 0.01077 x7.27703
luadist/dkjson 0.015 0.018 0.01559 x10.5338
vurv78/qjson 0.001 0.003 0.00148 x1
grafi-tt/lunajson 0.007 0.01 0.008645 x5.84122
Lua 5.3 (WSL : Windows 11)
11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
Name (Decode) Min Max Avg Avg / Best
actboy168/json 0.019036 0.024134 0.0204356 x1.63325
rxi/json 0.045677 0.059829 0.0487656 x3.89742
vurv78/qjson 0.01478 0.02029 0.0160733 x1.28461
luadist/dkjson 0.028986 0.038415 0.0314367 x2.51247
grafi-tt/lunajson 0.01162 0.015419 0.0125123 x1
Name (Encode) Min Max Avg Avg / Best
actboy168/json 0.016462 0.019902 0.0176806 x3.0031
rxi/json 0.016091 0.020716 0.0182224 x3.09512
vurv78/qjson 0.005352 0.008078 0.00588746 x1
luadist/dkjson 0.022643 0.04247 0.0249368 x4.23559
grafi-tt/lunajson 0.011779 0.014569 0.0128647 x2.1851

From here, you can see this library is fastest at encoding, running 8-10x faster than the most commonly used libraries.

Decoding is getting there. Currently balancing performance between PUC-Lua and Luajit.

qjson.lua's People

Contributors

vurv78 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

qjson.lua's Issues

Benchmarks

Need solid benchmarks. rxi/json.lua's benchmarks are unreliable, and I want to run them automatically here with github actions.

Add `null` encode case.

Since qjson.NULL exists now, you should be able to do this:

local json = require "qjson"

json.encode {
    xyz = json.NULL
}

and get

{"xyz":null}

Include lines of code in README stats

Probably want to give perspective as to why certain libraries are / can be so optimized.
Also might want to know if a library is worth trying to embed into a small project.

lunajson's decoder is ~500 lines of code, qjson's is ~140, rxi/json.lua is ~200

Testing

Want some tests using lest to ensure this actually follows the JSON spec, or at least specifies where it deviates.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.