{"id":15661115,"url":"https://github.com/ohler55/compare-go-json","last_synced_at":"2025-05-05T21:33:43.459Z","repository":{"id":38329817,"uuid":"281513480","full_name":"ohler55/compare-go-json","owner":"ohler55","description":"A comparison of several go JSON packages.","archived":false,"fork":false,"pushed_at":"2022-06-06T22:04:35.000Z","size":91,"stargazers_count":22,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T23:51:10.497Z","etag":null,"topics":["benchmarks","compare","go","json","jsonpath","parser"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ohler55.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-21T22:01:56.000Z","updated_at":"2024-11-17T02:48:20.000Z","dependencies_parsed_at":"2022-08-25T03:53:34.450Z","dependency_job_id":null,"html_url":"https://github.com/ohler55/compare-go-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/ohler55%2Fcompare-go-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohler55%2Fcompare-go-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohler55%2Fcompare-go-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohler55%2Fcompare-go-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ohler55","download_url":"https://codeload.github.com/ohler55/compare-go-json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252579993,"owners_count":21771248,"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":["benchmarks","compare","go","json","jsonpath","parser"],"created_at":"2024-10-03T13:25:55.951Z","updated_at":"2025-05-05T21:33:43.437Z","avatar_url":"https://github.com/ohler55.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Compare Go JSON\n\nNot all JSON tools cover the same features which make it difficult to\nselect a set of tools for a project. Here is an attempt to compare\nfeatures and benchmarks for a few of the JSON tools for Go.\n\n## Features\n\n| Feature                         | [go/json](https://golang.org/pkg/encoding/json/) | [fastjson](https://github.com/valyala/fastjson) | [jsoniter](https://github.com/json-iterator/go) | [OjG](https://github.com/ohler55/ojg) | [simdjson](https://github.com/minio/simdjson-go) | [gjson](https://github.com/tidwall/gjson)\n| ------------------------------- | ------------------ | ------------------ | ------------------ | ------------------ | ------------------ | ------------------ |\n| Parse []byte to simple go types | :white_check_mark: | :x:                | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark::boom: |\n| Validate                        | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |\n| Parse - io.Reader (large file)  | :white_check_mark: | :x:                | :white_check_mark: | :white_check_mark: | :x:                | :x:                |\n| Parse from file                 | :white_check_mark: | :x:                | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x:                |\n| Parse to structs                | :white_check_mark: | :x:                | :white_check_mark: | :white_check_mark: | :x:                | :x:                |\n| Parse to interface types        | :x:                | :x:                | :x:                | :white_check_mark: | :x:                | :x:                |\n| Multiple JSON file/stream       | :white_check_mark: | :x:                | :white_check_mark: | :white_check_mark: | :x:                | :x:                |\n| ndjson (newline separated)      | :white_check_mark: | :x:                | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x:                |\n| Marshal/Write                   | :white_check_mark: | :x:                | :white_check_mark: | :white_check_mark: | :x:                | :x:                |\n| JSON Builder                    | :x:                | :x:                | :x:                | :white_check_mark: | :x:                | :x:                |\n| JSONPath                        | :x:                | :x:                | :x:                | :white_check_mark: | :x:                | :x::small_blue_diamond: |\n| Data type converters            | :x:                | :x:                | :x:                | :white_check_mark: | :x:                | :x:                |\n| Simple Encoding Notation        | :x:                | :x:                | :x:                | :white_check_mark: | :x:                | :x:                |\n| Test coverage                   | --                 | 93%                | 21%                | 100%               | 57.4%              | 91.5%              |\n\n :boom: _gjson does not validate while parsing (try a number of 1.2e3e4) although it does catch that error in validation._\n\n :small_blue_diamond: _gjson has an alternative search feature_\n\n[_Details of each feature listed are at the bottom of the page_](#Feature-Explanations)\n\n# Benchmarks\n\n```\nParse string/[]byte to simple go types ([]interface{}, int64, string, etc)\n     json.Unmarshal          50142 ns/op        17776 B/op          334 allocs/op\n       oj.Parse              19453 ns/op         5691 B/op          364 allocs/op\n fastjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n jsoniter.Unmarshal          40849 ns/op        19656 B/op          451 allocs/op\n simdjson.Parse             119196 ns/op       141345 B/op          370 allocs/op\n    gjson.ParseBytes         53440 ns/op        20039 B/op          175 allocs/op\n\n       oj ██████████████████  2.58\n jsoniter ████████▌ 1.23\n     json ▓▓▓▓▓▓▓ 1.00\n    gjson ██████▌ 0.94\n simdjson ██▉ 0.42\n fastjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n\nValidate string/[]byte\n     json.Valid              12034 ns/op            0 B/op            0 allocs/op\n       oj.Validate            3802 ns/op            0 B/op            0 allocs/op\n fastjson.Validate            4521 ns/op            0 B/op            0 allocs/op\n jsoniter.Valid               8699 ns/op         2184 B/op          100 allocs/op\n simdjson.Validate           26498 ns/op       118842 B/op           20 allocs/op\n    gjson.Validate            3904 ns/op            0 B/op            0 allocs/op\n\n       oj ██████████████████████▏ 3.17\n    gjson █████████████████████▌ 3.08\n fastjson ██████████████████▋ 2.66\n jsoniter █████████▋ 1.38\n     json ▓▓▓▓▓▓▓ 1.00\n simdjson ███▏ 0.45\n\nIterate tokens in a string/[]byte\n     json.Decode             90142 ns/op        22600 B/op         1175 allocs/op\n       oj.Tokenize            8049 ns/op         1976 B/op          156 allocs/op\n fastjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n jsoniter.Decode             48138 ns/op        20360 B/op          456 allocs/op\n simdjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n    gjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n\n       oj ██████████████████████████████████████████████████████████████████████████████▍ 11.20\n jsoniter █████████████  1.87\n     json ▓▓▓▓▓▓▓ 1.00\n fastjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n simdjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n    gjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n\nUnmarshal string/[]byte to a struct\n     json.Unmarshal          39226 ns/op         2560 B/op           73 allocs/op\n       oj.Unmarshal          41857 ns/op         9355 B/op          456 allocs/op\n fastjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n jsoniter.Unmarshal          13005 ns/op         3137 B/op          170 allocs/op\n simdjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n    gjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n\n jsoniter █████████████████████  3.02\n     json ▓▓▓▓▓▓▓ 1.00\n       oj ██████▌ 0.94\n fastjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n simdjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n    gjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n\nMarshal simple types to string/[]byte\n     json.Marshal            51471 ns/op        17559 B/op          345 allocs/op\n       oj.JSON                6615 ns/op            0 B/op            0 allocs/op\n fastjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n jsoniter.Marshal            18855 ns/op         6299 B/op           63 allocs/op\n simdjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n    gjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n\n       oj ██████████████████████████████████████████████████████▍ 7.78\n jsoniter ███████████████████  2.73\n     json ▓▓▓▓▓▓▓ 1.00\n fastjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n simdjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n    gjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n\nMarshal a struct to string/[]byte\n     json.Marshal            11353 ns/op         3457 B/op            1 allocs/op\n       oj.Marshal             8453 ns/op         1712 B/op           44 allocs/op\n fastjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n jsoniter.Marshal            11315 ns/op         3466 B/op            2 allocs/op\n simdjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n    gjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n\n       oj █████████▍ 1.34\n jsoniter ███████  1.00\n     json ▓▓▓▓▓▓▓ 1.00\n fastjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n simdjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n    gjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n\nRead from single JSON file\n     json.Decode             85118 ns/op        32416 B/op          342 allocs/op\n       oj.ParseReader        28191 ns/op         9787 B/op          365 allocs/op\n fastjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n jsoniter.Decode             59635 ns/op        20327 B/op          456 allocs/op\n simdjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n    gjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n\n       oj █████████████████████▏ 3.02\n jsoniter █████████▉ 1.43\n     json ▓▓▓▓▓▓▓ 1.00\n fastjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n simdjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n    gjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n\nRead multiple JSON in a small log file (100MB)\n     json.Decode        1354784239 ns/op   1102470120 B/op     14810436 allocs/op\n       oj.ParseReader    668270061 ns/op    761294040 B/op     15402846 allocs/op\n fastjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n jsoniter.Decode        1131730647 ns/op   1178775816 B/op     19390099 allocs/op\n simdjson.ParseReader    679189142 ns/op   1398403912 B/op     13639254 allocs/op\n    gjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n\n       oj ██████████████▏ 2.03\n simdjson █████████████▉ 1.99\n jsoniter ████████▍ 1.20\n     json ▓▓▓▓▓▓▓ 1.00\n fastjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n    gjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n\nRead multiple JSON in a semi large log file (5GB)\n     json.Decode       88433748107 ns/op  28649383232 B/op    740520188 allocs/op\n       oj.ParseReader  38353089960 ns/op  11590577208 B/op    770140750 allocs/op\n fastjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n jsoniter.Decode       86478665854 ns/op  32465480800 B/op    969507711 allocs/op\n simdjson.ParseReader \u003e\u003e\u003e out of memory \u003c\u003c\u003c\n    gjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n\n       oj ████████████████▏ 2.31\n jsoniter ███████▏ 1.02\n     json ▓▓▓▓▓▓▓ 1.00\n fastjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n simdjson \u003e\u003e\u003e out of memory \u003c\u003c\u003c\n    gjson \u003e\u003e\u003e not supported \u003c\u003c\u003c\n\n Higher values (longer bars) are better in all cases. The bar graph compares the\n parsing performance. The lighter colored bar is the reference, the go json\n package.\n\nTests run on:\n OS:              Ubuntu 20.04.2 LTS\n Processor:       Intel(R) Core(TM) i7-8700 CPU\n Cores:           12\n Processor Speed: 3.20GHz\n Memory:          16 GB\n```\n\n## Feature Explanations\n\n - **Parse** parse a string to []byte slice in simple go types of\n   `[]interface`, `map[string]interface{}`, `string`, `float64`,\n   `int64`, `bool`, or `nil`. This support the use case of extracting\n   data from a JSON suitable for natigating as well as handing off to\n   other packages such as a database for storage.\n\n - **Validate** a string or []byte slice without extracting values.\n\n - **Read from io.Reader** indicates a source such as a socket or file\n   larger than will fit into memory can be parsed.\n\n - **Read from file** indicates a parser can read from a file if not\n   directly then using ioutils.\n\n - **Parse to structs** is the ability to reconstitute a struct type\n   from JSON.\n\n - **Parse to interface types** is the ability to reconstitutes types\n   even if they are included as interfaces in a containing struct or\n   slice.\n\n - **Multiple JSON** indicates a file or stream with multiple JSON\n   documents can be parsed. This is no restricted to the limited case\n   of exactly one JSON element per line. Encountered in database dumps\n   and load files.\n\n - **ndjson** is a multiple document JSON where each JSON document\n   must be on exactly one line. Found in log files.\n\n - **Marshal/Write** is the ability of the package to marshal go types\n   in JSON.\n\n - **JSON Builder** is the ability to create new data structures suitable for JSON encoding.\n\n - **[JSONPath](https://goessner.net/articles/JsonPath)** is the\n   ability to navigate data using JSONPath expressions.\n\n - **Data type converters** tools for converting from type to simple\n   data types. Basically marshalling and unmarshalling to simple types\n   instead of to JSON.\n\n - **[Simple Encoding Notation](https://github.com/ohler55/ojg/blob/develop/sen.md)** is\n   a lazy JSON format where quotes and commas are optional in most\n   cases. A merge of JSON and GraphQL formats for those of us that\n   don't want to be bothered with strict syntax checking.\n\n - **Parser Test coverage** percent unit test coverage of the parser\n   package. It does not include coverage of other package in the\n   offering.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fohler55%2Fcompare-go-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fohler55%2Fcompare-go-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fohler55%2Fcompare-go-json/lists"}