Skip to content

Commit 4a43d36

Browse files
updated README.md
1 parent d42a118 commit 4a43d36

1 file changed

Lines changed: 22 additions & 17 deletions

File tree

README.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
# lua-simdjson
2-
A basic lua binding to [simdjson](https://simdjson.org). The simdjson library is an incredibly fast JSON parser that uses SIMD instructions and fancy algorithms to parse JSON very quickly. It's been tested with LuaJIT 2.0/2.1 and Lua 5.1, 5.2, and 5.3 on linux
1+
# lua-simdjson (WIP)
2+
[![Build Status](https://travis-ci.org/FourierTransformer/lua-simdjson.svg?branch=master)](https://travis-ci.org/FourierTransformer/lua-simdjson)
3+
4+
A basic lua binding to [simdjson](https://simdjson.org). The simdjson library is an incredibly fast JSON parser that uses SIMD instructions and fancy algorithms to parse JSON very quickly. It's been tested with LuaJIT 2.0/2.1 and Lua 5.1, 5.2, 5.3, and 5.4 on linux/osx. It has a general parsing mode and a lazy mode that uses a JSON pointer.
35

46
Current simdjson version: 0.3.1
57

68
## Requirements
79
* lua-simdjson only works on 64bit systems.
8-
* a modern lua build environment with g++ and support for C++11
10+
* a lua build environment with support for C++11
11+
* g++ version 7+ and clang++ version 6+ or newer should work!
912

1013
## Parsing
1114
There are two main ways to parse JSON in lua-simdjson:
1215
1. With `parse`: this parses JSON and returns a lua table with the parsed values
13-
2. With `open`: this reads in the JSON and keeps it in simdjson's internal format. It can then be accessed using a JSON pointer (examples below)
16+
2. With `open`: this reads in the JSON and keeps it in simdjson's internal format. The values can then be accessed using a JSON pointer (examples below)
1417

1518
Both of these methods also have support to read files on disc with `parseFile` and `openFile` respectively. If handling JSON from disk, these methods should be used and are incredibly fast.
1619

@@ -40,7 +43,7 @@ local response = simdjson.parse([[
4043
}
4144
}
4245
]])
43-
print(response["Images"]["Width"])
46+
print(response["Image"]["Width"])
4447

4548
-- OR to parse a file from disk
4649
local fileResponse = simdjson.parseFile("jsonexamples/twitter.json")
@@ -52,7 +55,7 @@ print(fileResponse["statuses"][1]["id"])
5255
The `open` methods currently require the use of a JSON pointer, but are very quick.
5356
```lua
5457
local simdjson = require("simdjson")
55-
local response = simdjson.parse([[
58+
local response = simdjson.open([[
5659
{
5760
"Image": {
5861
"Width": 800,
@@ -68,30 +71,32 @@ local response = simdjson.parse([[
6871
}
6972
}
7073
]])
71-
print(response.at("Images/Width"))
74+
print(response:at("Image/Width"))
7275

7376
-- OR to parse a file from disk
74-
local fileResponse = simdjson.parseFile("jsonexamples/twitter.json")
75-
print(fileResponse.at("statuses/0/id") --using a JSON pointer
77+
local fileResponse = simdjson.open("jsonexamples/twitter.json")
78+
print(fileResponse:at("statuses/0/id")) --using a JSON pointer
7679

7780
```
7881
The `open` and `parse` codeblocks should print out the same values. It's worth noting that the JSON pointer indexes from 0.
7982

8083
This lazy style of using the simdjson data structure could also be used with array access in the future, and would result in ultra-fast JSON parsing.
8184

85+
## Error Handling
86+
lua-simdjson will error out with any errors from simdjson encountered while parsing. They are very good at helping identify what has gone wrong during parsing.
87+
8288
## Benchmarks
8389
TODO: add some benchmarks
8490

85-
## Caveats
86-
* there is no encoding/dumping a lua table to JSON (yet!)
87-
* it only works on 64 bit systems (possibly only Linux, more testing is needed)
91+
## Caveats & Alternatives
92+
* there is no encoding/dumping a lua table to JSON (yet! Most other lua JSON libraries can handle this)
93+
* it only works on 64 bit systems (untested on Windows...)
8894
* it builds a large binary. On a modern linux system, it ended up being \~200k (lua-cjson comes in at 42k)
89-
* since it's an external module, it's not quite as easy to just grab the file and go.
90-
* it needs a compiler that supports at least C++11
95+
* since it's an external module, it's not quite as easy to just grab the file and go (dkjson has you covered here!)
9196

92-
## Error Handling
93-
lua-simdjson will error out with any errors from simdjson encountered while parsing. They are fairly informative as to what has gone wrong during parsing.
97+
## Philosophy
98+
I plan to keep it fairly inline with what the original simdjson library is capable of doing, which really means not adding too many additional options. The big _thing_ that's missing so far is encoding a lua table to JSON. I may add in an encoder at some point (likely modified from an existing lua library). There are some rumours that simdjson _may_ support creating JSON structure in the future. If that happens, I would likely switch to it.
9499

95100
## Licenses
96101
* The jsonexamples, src/simdjson.cpp, src/simdjson.h are unmodified from the released version simdjson under the Apache License 2.0.
97-
* All other files/folders are apart of lua-cjson also under the Apache License 2.0.
102+
* All other files/folders are apart of lua-simdjson also under the Apache License 2.0.

0 commit comments

Comments
 (0)