{"id":17688250,"url":"https://github.com/neroist/jsonlines","last_synced_at":"2026-04-25T08:36:04.684Z","repository":{"id":231818410,"uuid":"655941229","full_name":"neroist/jsonlines","owner":"neroist","description":"Simple JSON Lines parser in Nim","archived":false,"fork":false,"pushed_at":"2023-06-21T07:09:37.000Z","size":86,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-29T15:01:40.899Z","etag":null,"topics":["json","json-lines","jsonlines","nim","nim-lang","nimble","parser","simple"],"latest_commit_sha":null,"homepage":"https://neroist.github.io/jsonlines/","language":"Nim","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/neroist.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}},"created_at":"2023-06-20T00:19:07.000Z","updated_at":"2023-06-20T00:21:13.000Z","dependencies_parsed_at":"2024-04-06T06:10:41.346Z","dependency_job_id":"ddfaaf8e-529c-4c6e-9490-0eb0eba931bd","html_url":"https://github.com/neroist/jsonlines","commit_stats":null,"previous_names":["neroist/jsonlines"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/neroist/jsonlines","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neroist%2Fjsonlines","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neroist%2Fjsonlines/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neroist%2Fjsonlines/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neroist%2Fjsonlines/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neroist","download_url":"https://codeload.github.com/neroist/jsonlines/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neroist%2Fjsonlines/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32255709,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-25T04:23:17.126Z","status":"ssl_error","status_checked_at":"2026-04-25T04:21:53.360Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","json-lines","jsonlines","nim","nim-lang","nimble","parser","simple"],"created_at":"2024-10-24T11:43:53.888Z","updated_at":"2026-04-25T08:36:04.662Z","avatar_url":"https://github.com/neroist.png","language":"Nim","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# jsonlines\n\nA simple [JSON Lines](https://jsonlines.org) (and NDJSON) parser library in Nim.\n\n\u003e See Also: \u003chttps://neroist.github.io/jsonlines/jsonlines.html\u003e\n\n---\n\nJSON Lines is a file format similar to JSON, except it can hold multiple\nJSON documents in a single file, which are delimited by newlines. It's a\nconvenient format for storing structured data that may be processed one\nrecord at a time and works well with unix-style text processing tools and\nshell pipelines. It's also a great format for log files, and a flexible\nformat for passing messages between cooperating processes.\n\nThis format has three main requirements:\n\n1. **UTF-8 Encoding.** (although this library doesn't check for that)\n\n2. **Each line is a valid JSON value.** The most common values will be objects\n   or arrays, although any JSON value is permitted. However, with this\n   library, you can also choose whether or not to ignore empty lines.\n\n3. **Line Separator is `'\\n'`.** `'\\r\\n'` is also supported because surrounding\n   white space is implicitly ignored when parsing JSON values.\n\nExamples:\n\n```json\n{\"name\": \"Gilbert\", \"wins\": [[\"straight\", \"7♣\"], [\"one pair\", \"10♥\"]]}\n{\"name\": \"Alexa\", \"wins\": [[\"two pair\", \"4♠\"], [\"two pair\", \"9♠\"]]}\n{\"name\": \"May\", \"wins\": []}\n{\"name\": \"Deloise\", \"wins\": [[\"three of a kind\", \"5♣\"]]}\n```\n\n```json\n{\"some\": \"thing\"}\n{\"foo\": 17, \"bar\": false, \"quux\": true}\n{\"may\": {\"include\": \"nested\", \"objects\": [\"and\", \"arrays\"]}}\n```\n\n\n## Parsing JSON Lines\n\nTo parse JSON Lines data, all you simply have to do is use the\n[parseJsonLines](https://neroist.github.io/jsonlines/jsonlines.html#parseJsonLines%2Cstring%2Cbool)\nproc.\n\n\n\n```nim\nlet jsonl = parseJsonLines(\"\"\"{\"some\": \"thing\"}\n{\"foo\": 17, \"bar\": false, \"quux\": true}\n{\"may\": {\"include\": \"nested\", \"objects\": [\"and\", \"arrays\"]}}\n\"\"\")\n\necho jsonl\n```\n\n\n```\n{\"some\":\"thing\"}\n{\"foo\":17,\"bar\":false,\"quux\":true}\n{\"may\":{\"include\":\"nested\",\"objects\":[\"and\",\"arrays\"]}}\n```\n\n\n\n\nThis parses the data into a simple JsonLines object, which has a nodes\nattribute, containing a seq of all the\n[JsonNodes](https://nim-lang.org/docs/json.html#JsonNode) in the document.\n\nThis proc also works with Streams!\n\n\n### Parsing from a file\n\n\u003e **⚠️ Note:** This functionality is not supported on the JS backend\n\nTo parse from a file, you can:\n\n1. Read the file and use [parseJsonLines](https://neroist.github.io/jsonlines/jsonlines.html#parseJsonLines%2Cstring%2Cbool)\n\n2. Create the file stream yourself and use [parseJsonLines](https://neroist.github.io/jsonlines/jsonlines.html#parseJsonLines%2CStream%2Cstring%2Cbool)\n\n3. Simply call [parseJsonLinesFile](https://neroist.github.io/jsonlines/jsonlines.html#parseJsonLinesFile%2Cstring) with the name/location of the file.\n\nExample for #3:\n\n**Example file `1.jsonl`**:\n\n```json\n[\"Name\", \"Session\", \"Score\", \"Completed\"]\n[\"Gilbert\", \"2013\", 24, true]\n[\"Alexa\", \"2013\", 29, true]\n[\"May\", \"2012B\", 14, false]\n[\"Deloise\", \"2012A\", 19, true]\n```\n\n**Nim code**:\n\n\n\n```nim\necho parseJsonLinesFile(\"1.jsonl\")\n```\n\n\n```\n[\"Name\",\"Session\",\"Score\",\"Completed\"]\n[\"Gilbert\",\"2013\",24,true]\n[\"Alexa\",\"2013\",29,true]\n[\"May\",\"2012B\",14,false]\n[\"Deloise\",\"2012A\",19,true]\n```\n\n\n\n\n## Retrieving JSON Data\n\nSince JSON Lines is simply just a list of JSON values seperated by newlines,\nit can be simply represented as a list of JsonNodes. the\n[`[]`](https://neroist.github.io/jsonlines/jsonlines.html#[]%2CJsonLines%2C)\noperator can be used to get the JsonNode at index `idx`, and the\n[`[]=`](https://neroist.github.io/jsonlines/jsonlines.html#[]%3D%2CJsonLines%2Cint%2C)\noperator can be used to set a JsonNode.\n\nExample:\n\n\n\n```nim\nconst data = \"\"\"\n{\"creator\": {\"handle\": \"Wendigoon\", \"display_name\": \"Wendigoon\"}, \"video\": {\"id\": \"gCUFztOkrEU\", \"views\": 2088488, \"title\": \"Dante's Purgatorio \u0026 The 9 Levels of Purgatory Explained\"}}\n{\"creator\": {\"handle\": \"TomScottGo\", \"display_name\": \"Tom Scott\"}, \"video\": {\"id\": \"BxV14h0kFs0\", \"views\": 65367317, \"title\": \"This Video Has 65,367,317 Views\"}}\n{\"creator\": {\"handle\": \"HBMmaster\", \"display_name\": \"jan Misali\"}, \"video\": {\"id\": \"qID2B4MK7Y0\", \"views\": 1272282, \"title\": \"a better way to count\"}}\n{\"creator\": {\"handle\": \"HBMmaster\", \"display_name\": \"jan Misali\"}, \"video\": {\"id\": \"2EZihKCB9iw\", \"views\": 272019, \"title\": \"what is toki pona? (toki pona lesson one)\"}}\n{\"creator\": {\"handle\": \"SarahZ\", \"display_name\": \"Sarah Z\"}, \"video\": {\"id\": \"ohFyOjfcLWQ\", \"views\": 3115062, \"title\": \"A Brief History of Homestuck\"}}\n\"\"\"\n\nlet jsonl2 = parseJsonLines(data)\n\necho jsonl2[3].pretty # retrieve value, but make it pretty\n\n# std/json is exported by jsonlines, so we can use\njsonl2[3] = %* {\n  \"creator\": {\n    \"handle\": \"sisterhoodofsalvationllc\",\n    \"display_name\": \"Sisterhood of Salvation, LLC\"\n  },\n\n  \"video\": {\n    \"id\": \"cX4SNX_UaZI\",\n    \"views\": 393,\n    \"title\": \"Awakened Waters (in partnership with SOS LLC)\"\n  }\n} # set value\n\necho \"\" # print newline to seperate values\n\necho jsonl2[3].pretty # echo new value, but make it pretty\n```\n\n\n```\n{\n  \"creator\": {\n    \"handle\": \"HBMmaster\",\n    \"display_name\": \"jan Misali\"\n  },\n  \"video\": {\n    \"id\": \"2EZihKCB9iw\",\n    \"views\": 272019,\n    \"title\": \"what is toki pona? (toki pona lesson one)\"\n  }\n}\n\n{\n  \"creator\": {\n    \"handle\": \"sisterhoodofsalvationllc\",\n    \"display_name\": \"Sisterhood of Salvation, LLC\"\n  },\n  \"video\": {\n    \"id\": \"cX4SNX_UaZI\",\n    \"views\": 393,\n    \"title\": \"Awakened Waters (in partnership with SOS LLC)\"\n  }\n}\n```\n\n\n\n\n## other stuff (i guess)\n\nill fix this whenever i feel a bit better.\n\nAnyways, heres some of the other stuff in this library:\n\n- `pretty()`: Prettifies JsonLines JsonLines by making it easier to view. However, this results in invalid JSON Lines.\n\n- `add()`: Add JsonNode to JsonLines object\n\n- `toJArray()`: Convert JsonLines into JSON array (JArray)\n\n- `toJsonLines()`: Convert openArray of JsonNodes to JsonLines\n\n- `jsonLines()`: Convenience iterator that parses string buffer line by line\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneroist%2Fjsonlines","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneroist%2Fjsonlines","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneroist%2Fjsonlines/lists"}