{"id":15045477,"url":"https://github.com/zalando-incubator/flatjson","last_synced_at":"2025-10-04T05:31:42.344Z","repository":{"id":57742391,"uuid":"84570853","full_name":"zalando-incubator/flatjson","owner":"zalando-incubator","description":"A fast JSON parser (and builder)","archived":true,"fork":false,"pushed_at":"2019-01-11T08:56:20.000Z","size":425,"stargazers_count":45,"open_issues_count":1,"forks_count":3,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-09-29T23:21:10.027Z","etag":null,"topics":["java","json","json-parser","jvm","utilities"],"latest_commit_sha":null,"homepage":"","language":"Java","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/zalando-incubator.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null}},"created_at":"2017-03-10T14:58:07.000Z","updated_at":"2023-11-10T20:52:29.000Z","dependencies_parsed_at":"2022-09-09T11:20:32.876Z","dependency_job_id":null,"html_url":"https://github.com/zalando-incubator/flatjson","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/zalando-incubator%2Fflatjson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zalando-incubator%2Fflatjson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zalando-incubator%2Fflatjson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zalando-incubator%2Fflatjson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zalando-incubator","download_url":"https://codeload.github.com/zalando-incubator/flatjson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235222543,"owners_count":18955327,"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":["java","json","json-parser","jvm","utilities"],"created_at":"2024-09-24T20:51:55.698Z","updated_at":"2025-10-04T05:31:36.933Z","avatar_url":"https://github.com/zalando-incubator.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# flatjson\n\nA fast [json](https://json.org) parser (and builder), written in java.\n\n![uyubi salt flats](flat.jpg)\n*photo: [yoann supertramp](https://500px.com/photo/172664473/) [CC-BY]*\n\n* [Features](#features)\n* [Performance](#performance)\n* [Installation](#installation)\n* [Usage](#usage)\n* [Contributing](#contributing)\n* [History](#history)\n* [License](#license)\n\n### Features\n\n* **efficient** \u0026mdash; allocates as few objects as possible\n* **easy to use** \u0026mdash; simple api, inspired by [minimal-json](https://github.com/ralfstx/minimal-json)\n* **fast** \u0026mdash; like a bat out of hell!\n\n\n### Performance\n\nthe following chart shows benchmark results for parsing a 72K sample file on my macbook pro (2,7 ghz intel core i5).\n\n![benchmark chart](benchmark1.png)\n\nflatjson outperforms some popular json parsers (gson, jackson) by 2x to 3x, and is even faster than boon (which is known to be pretty fast).\n\nnormally, we want to do something with json, once we've parsed it. the second benchmark simulates an event processing use case: parse the event, process the data (= reverse an array which makes up the bulk of the json document), then serialize the result back to a string.\n\n![benchmark chart](benchmark2.png)\n\nas the graph shows, flatjson shines even more here.\n\nyou can run these benchmark yourself with `./gradlew jmh` \u0026mdash; a full run takes a bit over an hour.\n\n\n#### So, what's the trick?\n\nflatjson does not build a parse tree, just an index overlay, which is stored in an integer array. json nodes are constructed on demand (= on first access). this way, lots of objects allocations are saved.\n\nwhen serializing json, flatjson handles unchanged subtrees by copying substrings directly from input to output, bypassing actual serialization as much as possible.\n\n### Installation\n\nflatjson is on Maven Central, simply add it as a gradle dependency:\n\n```\ncompile 'org.zalando:flatjson:1.1.0'\n```\n\n### Usage\n\n```java\nJson json = Json.parse(\"[42, true, \\\"hello\\\"]\");\n```\n\nwe can check which type of entity the returned `Json` object represents:\n\n```java\njson.isNumber(); // --\u003e false\njson.isObject(); // --\u003e false\njson.isArray(); // --\u003e true\n```\nfor each `isFoo` method, there is a matching `asFoo` accessor.\narrays are represented by lists of `Json` objects.\n\n```java\nList\u003cJson\u003e array = json.asArray();\narray.size(); // --\u003e 3\narray.get(0).asLong(); // --\u003e 42\narray.get(1).asBoolean(); // --\u003e true\narray.get(2).asString(); // --\u003e \"hello\"\n```\nthis list is mutable and allows manipulation of the json DOM:\n\n```java\narray.add(Json.value(false));\njson.toString(); // --\u003e \"[42,true,\\\"hello\\\",false]\"\n```\nyou can also build objects from scratch:\n\n```java\nJson test = Json.object();\nMap\u003cString, Json\u003e object = test.asObject();\nobject.put(\"color\", Json.value(\"blue\"));\nobject.put(\"size\", Json.value(39));\ntest.toString(); // --\u003e \"{\\\"color\\\":\\\"blue\\\",\\\"size\\\":39}\"\n```\nsame with arrays:\n\n```java\nJson test = Json.array();\nList\u003cJson\u003e array = test.asArray();\narray.add(Json.value(\"hello\"));\narray.add(Json.value(42));\ntest.toString(); // --\u003e \"[\\\"hello\\\",42]\"\n\n```\n\n### Contributing\n\ncontributions are welcome \u0026mdash; especially \n\n* reporting bugs\n* running the benchmarks in different environments (AMD, Azure, AWS, Google Cloud ...) and sharing the [results](benchmarks.txt)\n* adding your favorite json parser to the benchmarks \u0026mdash; can it beat flatjson?\n* adding more unit tests.\n\ni will not easily be persuaded to merge in major new features, though.\n\n\n### History\n\n##### 1.1.0 \u0026mdash; 2017-04-03\n* implemented `Visitor` pattern to interact with json\n* added `json.prettyPrint()` (implemented as `Visitor`)\n* `json.equals()` now based on `json.prettyPrint()`\n\n##### 1.0.1 \u0026mdash; 2017-03-17\n* support additional number types: `int`, `float`, `BigInteger`, `BigDecimal`\n\n##### 1.0 \u0026mdash; 2017-03-10\n* initial public release\n\n\n### License\n\n```\nThe MIT License (MIT)\n\nCopyright (c) 2017 Zalando SE\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzalando-incubator%2Fflatjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzalando-incubator%2Fflatjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzalando-incubator%2Fflatjson/lists"}