{"id":13796352,"url":"https://github.com/schollz/jsonstore","last_synced_at":"2025-05-13T00:30:47.711Z","repository":{"id":46511619,"uuid":"80050175","full_name":"schollz/jsonstore","owner":"schollz","description":"Simple thread-safe in-memory JSON key-store with persistent backend","archived":false,"fork":false,"pushed_at":"2019-03-13T02:28:20.000Z","size":39,"stargazers_count":135,"open_issues_count":4,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-05-20T15:12:00.442Z","etag":null,"topics":["json","keystore"],"latest_commit_sha":null,"homepage":null,"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/schollz.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":"2017-01-25T19:37:25.000Z","updated_at":"2024-03-15T17:31:33.000Z","dependencies_parsed_at":"2022-08-26T14:23:51.311Z","dependency_job_id":null,"html_url":"https://github.com/schollz/jsonstore","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schollz%2Fjsonstore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schollz%2Fjsonstore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schollz%2Fjsonstore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schollz%2Fjsonstore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/schollz","download_url":"https://codeload.github.com/schollz/jsonstore/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225159855,"owners_count":17430192,"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":["json","keystore"],"created_at":"2024-08-03T23:01:09.295Z","updated_at":"2024-11-18T10:31:15.174Z","avatar_url":"https://github.com/schollz.png","language":"Go","funding_links":[],"categories":["Go","Libraries"],"sub_categories":[],"readme":"# jsonstore  :convenience_store:\r\n\r\n[![GoDoc](https://godoc.org/github.com/schollz/jsonstore?status.svg)](https://godoc.org/github.com/schollz/jsonstore)\r\n\r\n*JSONStore* is a Go-library for a simple thread-safe in-memory JSON key-store with persistent backend. It's made for those times where you don't need a RDBMS like [MySQL](https://www.mysql.com/), or a NoSQL like [MongoDB](https://www.mongodb.com/) - basically when you just need a simple keystore. A really simple keystore. *JSONStore* is used in those times you don't need a distributed keystore like [etcd](https://coreos.com/etcd/docs/latest/), or\r\na remote keystore [Redis](https://redis.io/) or a local keystore like [Bolt](https://github.com/boltdb/bolt). Its really for those times where you just need a JSON file.\r\n\r\n## Usage\r\n\r\nFirst, install the library using:\r\n\r\n```\r\ngo get -u -v github.com/schollz/jsonstore\r\n```\r\n\r\nThen you can add it to your program. Check out the examples, or see below for basic usage:\r\n\r\n```golang\r\nks := new(jsonstore.JSONStore)\r\n\r\n// set a key to any object you want\r\ntype Human struct {\r\n  Name   string\r\n  Height float64\r\n}\r\nerr := ks.Set(\"human:1\", Human{\"Dante\", 5.4})\r\nif err != nil {\r\n  panic(err)\r\n}\r\n\r\n// Saving will automatically gzip if .gz is provided\r\nif err = jsonstore.Save(ks, \"humans.json.gz\"); err != nil {\r\n  panic(err)\r\n}\r\n\r\n// Load any JSON / GZipped JSON\r\nks2, err := jsonstore.Open(\"humans.json.gz\")\r\nif err != nil {\r\n  panic(err)\r\n}\r\n\r\n// get the data back via an interface\r\nvar human Human\r\nerr = ks2.Get(\"human:1\", \u0026human)\r\nif err != nil {\r\n  panic(err)\r\n}\r\nfmt.Println(human.Name) // Prints 'Dante'\r\n```\r\n\r\nThe datastore on disk is then contains:\r\n\r\n```bash\r\n$ zcat humans.json.gz\r\n{\r\n\"human:1\": \"{\\\"Name\\\":\\\"Dante\\\",\\\"Height\\\":5.4}\"\r\n}\r\n```\r\n\r\n\r\n**JSONStore** in the wild:\r\n\r\n- [schollz/urls](https://github.com/schollz/urls) - URL shortening\r\n\r\n# Dev\r\n\r\nBenchmark against using Redis and BoltDB as KeyStores using Go1.8 (Intel i5-4310U CPU @ 2.00GHz). Take away is that setting/getting is faster in *JSONStore* (because its just a map), but opening is much slower (because its a file that is read into memory). So don't use this if you have to store 1,000,000+ things!\r\n\r\n```\r\n$ go test -bench=. tests/redis/* \u003e redis.txt\r\n$ go test -bench=. tests/bolt/* \u003e bolt.txt\r\n$ go test -bench=. \u003e jsonstore.txt\r\n$ benchcmp bolt.txt jsonstore.txt\r\nbenchmark                old ns/op     new ns/op     delta\r\nBenchmarkSet-4           5471747       1847          -99.97%\r\nBenchmarkGet-4           2424          1479          -38.99%\r\nBenchmarkOpen100-4       11168         148035        +1225.53%\r\nBenchmarkOpen10000-4     10095         19722376      +195267.77%\r\n$ benchcmp redis.txt jsonstore.txt\r\nbenchmark                old ns/op     new ns/op     delta\r\nBenchmarkSet-4           24717         1847          -92.53%\r\nBenchmarkGet-4           22561         1479          -93.44%\r\nBenchmarkOpen100-4       6221          148035        +2279.60%\r\nBenchmarkOpen10000-4     4951          19722376      +398251.36%\r\n```\r\n\r\n# License\r\n\r\nMIT\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschollz%2Fjsonstore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fschollz%2Fjsonstore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschollz%2Fjsonstore/lists"}