{"id":16939446,"url":"https://github.com/a8m/djson","last_synced_at":"2025-04-05T01:08:41.781Z","repository":{"id":38272833,"uuid":"68937386","full_name":"a8m/djson","owner":"a8m","description":"Fast Go decoder for dynamic JSON","archived":false,"fork":false,"pushed_at":"2017-05-09T17:07:05.000Z","size":619,"stargazers_count":597,"open_issues_count":7,"forks_count":21,"subscribers_count":20,"default_branch":"master","last_synced_at":"2024-10-14T21:04:47.209Z","etag":null,"topics":["decoder","go","json","json-parser","performance"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/a8m.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}},"created_at":"2016-09-22T15:54:05.000Z","updated_at":"2024-09-27T11:31:34.000Z","dependencies_parsed_at":"2022-08-18T15:22:36.585Z","dependency_job_id":null,"html_url":"https://github.com/a8m/djson","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a8m%2Fdjson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a8m%2Fdjson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a8m%2Fdjson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a8m%2Fdjson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/a8m","download_url":"https://codeload.github.com/a8m/djson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247271532,"owners_count":20911587,"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":["decoder","go","json","json-parser","performance"],"created_at":"2024-10-13T21:04:46.385Z","updated_at":"2025-04-05T01:08:41.764Z","avatar_url":"https://github.com/a8m.png","language":"Go","readme":"\u003cp align=\"center\"\u003e\n\u003cimg \n    src=\"assets/logo.png\" width=\"240\" height=\"78\" border=\"0\" alt=\"DJSON\"\u003e\n\u003cbr/\u003e\u003cbr/\u003e\n\u003ca href=\"https://godoc.org/github.com/a8m/djson\"\u003e\u003cimg src=\"https://img.shields.io/badge/api-reference-blue.svg?style=flat-square\" alt=\"GoDoc\"\u003e\u003c/a\u003e\n\u003ca href=\"https://travis-ci.org/a8m/djson\"\u003e\u003cimg src=\"https://img.shields.io/travis/a8m/djson.svg?style=flat-square\"\nalt=\"Build Status\"\u003e\u003c/a\u003e\n\u003ca href=\"LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square\" alt=\"LICENSE\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nDJSON is a JSON decoder for Go that is ___2~ to 3~ times faster___ than\nthe standard `encoding/json` and the existing solutions, when dealing with\narbitrary JSON payload. [See benchmarks below](#benchmark).  \nIt is a good approach for people who are using `json.Unmarshal` together\nwith `interface{}`, don't know what the schema is, and still want good\nperformance with minimal changes.\n\n### Motivation\nWhile searching for a JSON parser solution for my projects, that is faster than the standard library, with zero reflection tests, allocates less memory and is still safe(I didn't want the `\"unsafe\"` package in my production code, in order to reduce memory consumption).  \nI found that almost all implemtations are just wrappers around the standard library\nand aren't fast enough for my needs.  \nI encountered two projects: [ujson](https://github.com/mreiferson/go-ujson) that is the UltraJSON implementation\nand [jsonparser](https://github.com/buger/jsonparser), that is a pretty awesome project.  \nujson seems to be faster than `encoding/json` but still doesn't meet my requirements.  \njsonparser seems to be really fast, and I even use it for some of my new projects.  \nHowever, its API is different, and I would need to change too much of my\ncode in order to work with it.  \nAlso, for my processing work that involves `ETL`, changing and setting new\nfields on the JSON object, I need to transform the `jsonparser`\nresult to `map[string]interface{}` and it seems that it loses its power.\n\n### Advantages and Stability\nAs you can see in the [benchmark below](#benchmark), DJSON is faster and allocates less\nmemory than the other alternatives.  \nThe current version is `1.0.0-alpha.1`, and I'm waiting to hear from you\nif there are any issues or bug reports, to make it stable.  \n(comment: there is a test file named `decode_test` that contains a [test case](https://github.com/a8m/djson/blob/master/decode_test.go#L104) that\ncompares the results to `encoding/json` - feel free to add more values if you find they are important)  \nI'm also plaining to add the `DecodeStream(io.ReaderCloser)` method(or `NewDecoder(io.ReaderCloser)`), to support stream decoding\nwithout breaking performance.\n\n\n### Benchmark\nThere are 3 benchmark types: [small](#small-payload), [medium](#medium-payload) and [large](#large-payload) payloads.  \nAll the 3 are taken from the `jsonparser` project, and they try to simulate a real-life usage. \nEach result from the different benchmark types is shown in a metric table below.\nThe lower the metrics are, the better the result is.\n__Time/op__ is in nanoseconds, __B/op__ is how many bytes were allocated\nper op and __allocs/op__ is the total number of memory allocations.  \nBenchmark results that are better than `encoding/json` are marked in bold text.  \nThe Benchmark tests run on AWS EC2 instance(c4.xlarge). see: [screenshots](https://github.com/a8m/djson/tree/master/assets)\n\nCompared libraries:\n- https://golang.org/pkg/encoding/json\n- https://github.com/Jeffail/gabs\n- https://github.com/bitly/go-simplejson\n- https://github.com/antonholmquist/jason\n- https://github.com/mreiferson/go-ujson\n- https://github.com/ugorji/go/codec\n\n#### Small payload\nEach library in the test gets a small payload to process that weighs 134 bytes.  \nYou can see the payload [here](https://github.com/a8m/djson/blob/master/benchmark/benchmark_fixture.go#L3), and the test screenshot [here](https://github.com/a8m/djson/blob/master/assets/bench_small.png).\n\n| __Library__                 | __Time/op__   | __B/op__ | __allocs/op__ |\n|-----------------------------|-------------- |----------|---------------|\n| encoding/json               |    8646       |   1993   |   60          |\n| ugorji/go/codec             |    9272       |   4513   |   __41__      |\n| antonholmquist/jason        |    __7336__   |   3201   |   __49__      |\n| bitly/go-simplejson         |    __5253__   |   2241   |   __36__      |\n| Jeffail/gabs                |    __4788__   | __1409__ |   __33__      |\n| mreiferson/go-ujson         |    __3897__   | __1393__ |   __35__      |\n| a8m/djson                   |    __2534__   | __1137__ |   __25__      |\n| a8m/djson.[AllocString][as] |    __2195__   | __1169__ |   __13__      |\n\n\n#### Medium payload\nEach library in the test gets a medium payload to process that weighs 1.7KB.  \nYou can see the payload [here](https://github.com/a8m/djson/blob/master/benchmark/benchmark_fixture.go#L5), and the test screenshot [here](https://github.com/a8m/djson/blob/master/assets/bench_medium.png).\n\n| __Library__                  | __Time/op__    | __B/op__ | __allocs/op__  |\n|------------------------------|----------------|-----------|---------------|\n| encoding/json                |    42029       |   10652   |   218         |\n| ugorji/go/codec              |    65007       |   15267   |   313         |\n| antonholmquist/jason         |    45676       |   17476   |   224         |\n| bitly/go-simplejson          |    45164       |   17156   |   219         |\n| Jeffail/gabs                 |    __41045__   | __10515__ |   __211__     |\n| mreiferson/go-ujson          |    __33213__   |   11506   |   267         |\n| a8m/djson                    |    __22871__   | __10100__ |   __195__     |\n| a8m/djson.[AllocString][as]  |    __19296__   | __10619__ |   __87__      |\n\n#### Large payload\nEach library in the test gets a large payload to process that weighs 28KB.  \nYou can see the payload [here](https://github.com/a8m/djson/blob/master/benchmark/benchmark_fixture.go#L7), and the test screenshot [here](https://github.com/a8m/djson/blob/master/assets/bench_large.png).\n\n| __Library__                 | __Time/op__    | __B/op__   | __allocs/op__  |\n|-----------------------------|----------------|------------|----------------|\n| encoding/json               |    717882      |   212827   |   3247         |\n| ugorji/go/codec             |    1052347     |   239130   |   4426         |\n| antonholmquist/jason        |    751910      |   277931   |   3257         |\n| bitly/go-simplejson         |    753663      |   277628   |   3252         |\n| Jeffail/gabs                |    __714304__  | __212740__ |   __3241__     |\n| mreiferson/go-ujson         |    __599868__  |   235789   |   4057         |\n| a8m/djson                   |    __437031__  | __210997__ |   __2932__     |\n| a8m/djson.[AllocString][as] |    __372382__  |   214053   |   __1413__     |\n\n\n### LICENSE\nMIT\n\n[as]: https://github.com/a8m/djson/blob/master/decode.go#L25\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa8m%2Fdjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fa8m%2Fdjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa8m%2Fdjson/lists"}