{"id":13420586,"url":"https://github.com/cloudflare/lua-resty-json","last_synced_at":"2025-04-04T21:10:49.400Z","repository":{"id":23207227,"uuid":"26564065","full_name":"cloudflare/lua-resty-json","owner":"cloudflare","description":"json lib for lua and C","archived":false,"fork":false,"pushed_at":"2024-10-16T01:11:14.000Z","size":91,"stargazers_count":167,"open_issues_count":3,"forks_count":33,"subscribers_count":32,"default_branch":"master","last_synced_at":"2024-10-29T19:58:52.081Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloudflare.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-11-13T01:07:51.000Z","updated_at":"2024-10-15T21:13:31.000Z","dependencies_parsed_at":"2024-12-14T08:06:15.168Z","dependency_job_id":"3c7e3401-b8fd-43fd-8cd4-276bd6f0c395","html_url":"https://github.com/cloudflare/lua-resty-json","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Flua-resty-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Flua-resty-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Flua-resty-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Flua-resty-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloudflare","download_url":"https://codeload.github.com/cloudflare/lua-resty-json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247249532,"owners_count":20908212,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T22:01:36.828Z","updated_at":"2025-04-04T21:10:49.380Z","avatar_url":"https://github.com/cloudflare.png","language":"C","funding_links":[],"categories":["TODO scan for Android support in followings","Third Modules","Libraries","Rust Modules","Frameworks \u0026 Libraries"],"sub_categories":["C Modules","Lua Modules","Lua Libraries"],"readme":"lua-resty-json\n==============\n\nJson lib for lua and C. The C interface is depicted by `ljson_parser.h`;\nwhile the Lua interface is implemented by `json_decoder.lua`. The lua\ninterface is built on top of C implementation, and it's implemented\nusing FFI instead of Lua C-API.\n\nFollowing is an example of Lua usage:\n```lua\nlocal ljson_decoder = require 'json_decoder'\nlocal instance = ljson_decoder.create()\nlocal result, err = ljson_decoder.parse(instance, line)\n```\nPerformance\n-----------\n\nAs of I write this README.md, I compare this work against cjson using\nfew real-world json strings. For string-array intensive jsons, our decoder\nis normally 30% - 50% ahead of cjson. While for the hash-table intensive\ninput, we are only 10-30% better. In an extreme example where there is\na super long string, we see 5X speedup. The performance is measured with\nluajit 2.1.\n\nSo far we pay lots of attention to string handling, and did not get chance to\nimprove following aspects:\n- Parse floating point number quickly. so far we rely on `strtod()`\n  to do the dirty job. Unfortunately, the `strtod()` seems to be pretty\n  slow.\n\n- Efficiently skip white-spaces between tokens.\n\n- More efficient memory allocation. We are currently using `mempool`\n  which allocate a big chunk and the subsequent memory allocation requests\n  are served by carving block out of the chunk. It works pretty well\n  for small to medium-sized `JSON` input (say under `100k` in size);\n  however, the memory allocation overhead is still high (primarily due to\n  the cost of allocating big chunks) for big `JSON`s.\n\nFloating Point Number\n--------------------\nThe way we handle following situations may not be what you expect, but\nthe `JSON` SPEC does not seem to articulate how to handle these situations\nright either.\n\n- literal `-0` is interpreted as integer `0`, instead of floating point\n  `0.0`.\n\n-  `-0.0` is interperted as floating point `-0.0`.\n- If a literal is beyond the range of double-precision, we consider it\n  as overflow/underflow; we do not try to represent the literal using\n  `long double` or `quadruple`.\n\n- We rely on `strtod()` to parse literal (in strict mode), which, I guess,\n  is using default rounding mode or the mode designated by the appliction\n  which call the decoder.\n\n- We try to represent literals in signed 64-bit interger whenever possible.\n  But the numbers like `1E6` is still represented as floating point as we\n  currently rely on `strtod()` for handling scientific notation.\n\nTODO\n----\n- Continue to improve floating point parsing.\n- Improve testing, and add more testing.\n- Improve hashtab parsing performance (I almost have not yet got chance\n  tune its performance  when I write this comment).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudflare%2Flua-resty-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloudflare%2Flua-resty-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudflare%2Flua-resty-json/lists"}