{"id":18840236,"url":"https://github.com/maxim2266/tojson","last_synced_at":"2025-09-03T05:32:12.747Z","repository":{"id":151956902,"uuid":"342835942","full_name":"maxim2266/tojson","owner":"maxim2266","description":"Convert text to JSON via regular expression.","archived":false,"fork":false,"pushed_at":"2021-03-01T16:40:47.000Z","size":5,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-08T02:48:26.496Z","etag":null,"topics":["convert-to-json","json","log-analysis","log-parser","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maxim2266.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,"publiccode":null,"codemeta":null}},"created_at":"2021-02-27T11:04:00.000Z","updated_at":"2023-09-26T18:19:56.000Z","dependencies_parsed_at":"2023-06-10T02:30:43.508Z","dependency_job_id":null,"html_url":"https://github.com/maxim2266/tojson","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/maxim2266%2Ftojson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxim2266%2Ftojson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxim2266%2Ftojson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxim2266%2Ftojson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxim2266","download_url":"https://codeload.github.com/maxim2266/tojson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231838544,"owners_count":18434145,"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":["convert-to-json","json","log-analysis","log-parser","python3"],"created_at":"2024-11-08T02:46:55.964Z","updated_at":"2024-12-30T09:41:12.172Z","avatar_url":"https://github.com/maxim2266.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tojson\n\n[![License: BSD 3 Clause](https://img.shields.io/badge/License-BSD_3--Clause-yellow.svg)](https://opensource.org/licenses/BSD-3-Clause)\n\nConvert text to JSON via regular expression.\n\n#### Usage:\n```\ntojson REGEX\n```\n\nTake input text from STDIN and convert it to JSON via the given Python regular\nexpression REGEX. Each line of the input is searched for the first match of the\nregular expression and converted to a JSON object using names of the capturing\ngroups as keys, and their corresponding captures as values. Unnamed capturing\ngroups and groups that did not match are ignored. Each input line is stripped\nof any trailing whitespace before applying REGEX. Output always goes to STDOUT.\n\nBy default, in each output object all values are JSON strings, unless the\ncapturing group name has \"__N\" suffix, in which case the program makes an attempt\nto convert the value to a JSON number, or \"__B\" suffix to convert the value to\nJSON \"true\" or \"false\". In either case, the suffix is removed from the key, and\nfailed conversions leave values as strings. The boolean conversion treats strings\nlike \"true\" or \"yes\" as JSON \"true\", and strings like \"false\" and \"no\" as JSON\n\"false\", case-insensitive.\n\nTypical use cases include parsing plain text log files or Unix commands output\nto extract useful information and convert it to JSON for further processing.\n\n#### Example\n```sh\n▶ ps -u root -o pid,%cpu,%mem,args \\\n| tojson '^\\s*(?P\u003cpid__N\u003e\\d+)\\s+(?P\u003ccpu__N\u003e\\d+\\.\\d+)\\s+(?P\u003cmem__N\u003e\\d+\\.\\d+)\\s+(?P\u003ccmd\u003e[^[].+)$'\n```\n\nOutput:\n\n```JSON\n[ {\"cmd\": \"/sbin/init splash\", \"pid\": 1, \"cpu\": 0.0, \"mem\": 0.1}\n, {\"cmd\": \"/lib/systemd/systemd-journald\", \"pid\": 517, \"cpu\": 0.0, \"mem\": 0.2}\n, {\"cmd\": \"bpfilter_umh\", \"pid\": 543, \"cpu\": 0.0, \"mem\": 0.0}\n, {\"cmd\": \"/lib/systemd/systemd-udevd\", \"pid\": 554, \"cpu\": 0.0, \"mem\": 0.0}\n, {\"cmd\": \"/usr/lib/accountsservice/accounts-daemon\", \"pid\": 809, \"cpu\": 0.0, \"mem\": 0.1}\n, {\"cmd\": \"/usr/sbin/acpid\", \"pid\": 811, \"cpu\": 0.0, \"mem\": 0.0}\n...\n]\n```\n\n#### Installation\nJust copy `tojson` file to a directory included in the `$PATH` environment variable.\n\n#### Status\nTested on Linux Mint 20.1 with Python 3.8.5.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxim2266%2Ftojson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxim2266%2Ftojson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxim2266%2Ftojson/lists"}