{"id":19635864,"url":"https://github.com/tozd/regex2json","last_synced_at":"2026-02-12T05:06:59.177Z","repository":{"id":174827520,"uuid":"652841446","full_name":"tozd/regex2json","owner":"tozd","description":"Convert text to JSON using only regular expressions Read-only mirror of https://gitlab.com/tozd/regex2json","archived":false,"fork":false,"pushed_at":"2024-12-08T09:36:23.000Z","size":116,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-30T10:11:21.518Z","etag":null,"topics":["go","json","regexp"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tozd.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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,"publiccode":null,"codemeta":null},"funding":{"github":["plast8","mitar"]}},"created_at":"2023-06-12T22:55:02.000Z","updated_at":"2024-12-08T09:36:27.000Z","dependencies_parsed_at":"2023-07-09T07:15:51.511Z","dependency_job_id":"2bd860f6-e1d2-4b87-974a-86875ab092dc","html_url":"https://github.com/tozd/regex2json","commit_stats":null,"previous_names":["tozd/regex2json"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tozd%2Fregex2json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tozd%2Fregex2json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tozd%2Fregex2json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tozd%2Fregex2json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tozd","download_url":"https://codeload.github.com/tozd/regex2json/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251321728,"owners_count":21570784,"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":["go","json","regexp"],"created_at":"2024-11-11T12:27:19.271Z","updated_at":"2026-02-12T05:06:59.171Z","avatar_url":"https://github.com/tozd.png","language":"Go","funding_links":["https://github.com/sponsors/plast8","https://github.com/sponsors/mitar"],"categories":[],"sub_categories":[],"readme":"# Convert text to JSON using only regular expressions\n\n[![pkg.go.dev](https://pkg.go.dev/badge/gitlab.com/tozd/regex2json)](https://pkg.go.dev/gitlab.com/tozd/regex2json)\n[![Go Report Card](https://goreportcard.com/badge/gitlab.com/tozd/regex2json)](https://goreportcard.com/report/gitlab.com/tozd/regex2json)\n[![pipeline status](https://gitlab.com/tozd/regex2json/badges/main/pipeline.svg?ignore_skipped=true)](https://gitlab.com/tozd/regex2json/-/pipelines)\n[![coverage report](https://gitlab.com/tozd/regex2json/badges/main/coverage.svg)](https://gitlab.com/tozd/regex2json/-/graphs/main/charts)\n\nMain motivation for this tool is to convert traditional text-based (and line-based) logs to JSON\nfor programs which do not support JSON logs themselves.\nIt can be used in online manner (pipelining output of the program into regex2json, e.g., as log\nprocessor in [runit](http://smarden.org/runit/) and [dinit](https://gitlab.com/tozd/dinit) init systems)\nor offline manner (to process logs stored in files).\nBut the tool is more general and can enable any workflow where\nyou prefer operating on JSON instead of text. It works especially great when combined with\n[jq](https://jqlang.github.io/jq/).\n\nFeatures:\n\n- Reads stdin line by line, converting each line to JSON to stdout.\n- Supports transformations of matched capture groups by specifying the transformation as capture group's name.\n- Transformation consists of a series of operators (e.g., parsing numbers, timestamps, creating arrays and objects).\n- Supports regexp matching a line multiple times, combining all matches into one JSON.\n\n## Installation\n\n[Releases page](https://gitlab.com/tozd/regex2json/-/releases)\ncontains a list of stable versions. Each includes:\n\n- Statically compiled binaries.\n- Docker images.\n\nYou should just download/use the latest one.\n\nThe tool is implemented in Go. You can also use `go install` to install the latest stable (released) version:\n\n```sh\ngo install gitlab.com/tozd/regex2json/cmd/regex2json@latest\n```\n\nTo install the latest development version (`main` branch):\n\n```sh\ngo install gitlab.com/tozd/regex2json/cmd/regex2json@main\n```\n\n## Usage\n\nregex2json reads lines from stdin, matching every line with the provided regexp.\nIf line matches, values from captured named groups are mapped into output JSON\nwhich is then written out to stdout. If the line does not match, it is written\nto stderr.\n\nCapture groups' names are compiled into Expressions and describe how are matched\nvalues mapped and transformed into output JSON. See\n[Expression](https://pkg.go.dev/gitlab.com/tozd/regex2json#Expression)\nfor details on the syntax and\n[Library](https://pkg.go.dev/gitlab.com/tozd/regex2json#Library)\nfor available operators.\n\nAny error (e.g., a failed expression) is logged to stderr while the rest of the\noutput JSON is still written out.\n\nIf regexp can match multiple times per line, all matches are combined together\ninto the same one JSON output per line.\n\nUsage:\n\n```sh\nregex2json \u003cregexp\u003e\n```\n\nExample:\n\n```sh\n$ while true; do LC_ALL=C date; sleep 1; done | regex2json \"(?P\u003cdate___time__UnixDate__RFC3339\u003e.+)\"\n{\"date\":\"2023-06-13T11:26:45Z\"}\n{\"date\":\"2023-06-13T11:26:46Z\"}\n{\"date\":\"2023-06-13T11:26:47Z\"}\n```\n\nExample:\n\n\u003c!-- markdownlint-disable MD013 --\u003e\n\n```sh\n$ echo '192.168.0.100 - - [13/Jun/2023:13:15:13 +0000] \"GET /index.html HTTP/1.1\" 200 1234 \"-\" \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36\"' | \\\n  regex2json '^(?P\u003caddress\u003e\\S+) - (?P\u003cuser\u003e\\S+) \\[(?P\u003ctime___time__Nginx__RFC3339\u003e[\\w:/]+\\s[+\\-]\\d{4})\\] \"(?P\u003cmethod\u003e\\S+)\\s?(?P\u003curl\u003e\\S+)?\\s?(?P\u003chttp\u003e\\S+)?\" (?P\u003cstatus___int\u003e\\d{3}) (?:(?P\u003csize___int\u003e\\d+)|-) \"(?P\u003creferrer\u003e[^\"]*)\" \"(?P\u003cagent\u003e[^\"]*)\"'\n{\"address\":\"192.168.0.100\",\"agent\":\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36\",\"http\":\"HTTP/1.1\",\"method\":\"GET\",\"referrer\":\"-\",\"size\":1234,\"status\":200,\"time\":\"2023-06-13T13:15:13Z\",\"url\":\"/index.html\",\"user\":\"-\"}\n```\n\n\u003c!-- markdownlint-enable MD013 --\u003e\n\n### As a package\n\nThis is also a Go package. You can add it to your project using `go get`:\n\n```sh\ngo get gitlab.com/tozd/regex2json\n```\n\nIt requires Go 1.23 or newer.\n\nSee full package documentation on [pkg.go.dev](https://pkg.go.dev/gitlab.com/tozd/regex2json)\non using regex2json as a Go package.\n\n## Contributing\n\nFeel free to make a merge-request add more time layouts and/or operators.\n\n## Which regular expression syntax is supported?\n\nregex2json is implemented in Go and uses its [standard regexp package](https://pkg.go.dev/regexp/syntax)\nfor parsing and compiling regular expressions.\n\n## Why is syntax of transformations so awkward?\n\nThis is a consequence of the limitation on which characters can be in a capture group name in Go\n(`[A-Za-z0-9_]+`).\nSee [this issue](https://github.com/golang/go/issues/60784) for more details.\n\n## Related projects\n\n- [jc](https://github.com/kellyjonbrazil/jc) – jc enables the same idea of converting text-based output of\n  programs into JSON, but its focus is to support popular programs out of the box. regex2json enables quick\n  transformations by providing a regexp with expressions how captured groups are transformed into JSON.\n\n## GitHub mirror\n\nThere is also a [read-only GitHub mirror available](https://github.com/tozd/regex2json),\nif you need to fork the project there.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftozd%2Fregex2json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftozd%2Fregex2json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftozd%2Fregex2json/lists"}