{"id":21028047,"url":"https://github.com/d2r2/jsonc-bash","last_synced_at":"2026-01-18T13:28:21.421Z","repository":{"id":75776884,"uuid":"361334432","full_name":"d2r2/jsonc-bash","owner":"d2r2","description":"JSON and JSONC (JSON with comments) bash parser.","archived":false,"fork":false,"pushed_at":"2024-06-08T08:21:22.000Z","size":21,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-03T04:44:05.070Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","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/d2r2.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-04-25T04:56:16.000Z","updated_at":"2024-06-08T08:21:26.000Z","dependencies_parsed_at":"2023-06-07T16:30:58.492Z","dependency_job_id":null,"html_url":"https://github.com/d2r2/jsonc-bash","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/d2r2/jsonc-bash","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d2r2%2Fjsonc-bash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d2r2%2Fjsonc-bash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d2r2%2Fjsonc-bash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d2r2%2Fjsonc-bash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/d2r2","download_url":"https://codeload.github.com/d2r2/jsonc-bash/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d2r2%2Fjsonc-bash/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28536753,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T13:04:05.990Z","status":"ssl_error","status_checked_at":"2026-01-18T13:01:44.092Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":[],"created_at":"2024-11-19T11:53:45.092Z","updated_at":"2026-01-18T13:28:21.384Z","avatar_url":"https://github.com/d2r2.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"JSON/JSONC bash parser\n======================\n\nAbout\n-----\n\nLibrary `json.sh` allows you to parse JSON and JSONC (JSON superset with comments) formats in BASH and manipulate the parsed data to quickly select and search results.\nThis library does not claim to be high performance, but has been tested with JSON/JSONC configuration files on x86 and ARM Linux devices.\n\nFeatures\n--------\n\n* compatible with standard JSON and unofficial JSONC formats\n* no dependencies on any libraries (only standard BASH environment)\n* incremental single-pass parsing\n* library code is covered with unit-tests\n* allow easily manipulate with parsed JSON data in BASH:\n  * select values in XML XPath style\n  * get JSON array size and index JSON array content\n\nCompliance with the standard\n----------------------------\n\nThere are a lot of discussions that JSON standard is not clearly defined in some parts over the years, and parsers may differ from each other in some tricky cases.\nSo I just put here briefly what supported and how:\n\n* Objects and Arrays\n* Strings (as keys and values):\n  * Verify escaped characters\n  * Verify escaped Unicode symbol structure (4 chars and all must be hex)\n* Primitives:\n  * Strictly defined that primitives should start as a number, true, false or null\n* Permissive trailing commas: arrays and objects may contain commas (,) before closing brackets (]})\n* C-style comments are allowed as JSONC extension:\n  * One line comment starting with //\n  * Multiline comments with /* */\n\nUsage\n-----\n\nThe parser itself is located in the file `json.sh`.\n\nYou can test parser from command line with the script `examples/json_parse_file.sh` to parse any JSON/JSONC file to get results (debug tokens output).\n\nTo embed the parser to your BASH decision, please, read explanation below.\n\nLet's parse real JSON data:\n\n``` json\n{\"menu\": {\n  \"id\": \"file\",\n  \"type\": \"Word document\",\n  \"popup\": {\n    \"menuitem\": [\n      {\"value\": \"New\", \"onclick\": \"CreateNewDoc\", \"args\": [null, true, false, \"\\u042Fndex\" ] },\n      {\"value\": \"Open\", \"onclick\": \"OpenDoc\", \"args\": [1, \"some text\", 3.1415926] },\n      {\"value\": \"Close\", \"onclick\": \"CloseDoc\"}\n    ],\n  },\n}}\n```\n\nFirst, load library in your BASH script:\n\n``` bash\n# Load json library\nsource ./json.sh\n```\n\nThen, try to parse JSON taken from file:\n\n``` bash\nparse_json \"\u003cpath to json file\u003e\"; retval=$?\nif [[ $retval -ne 0 ]]; then\n\techo \"Error parsing JSON in line $JSON_LINE_ERROR\" 1\u003e\u00262\n\texit 1\nfi\n```\n\n, either if we want to read JSON from pipe:\n\n``` bash\nparse_json_from_pipe \u003c \u003c(func_return_heredoc_with_json); retval=$?\nif [[ $retval -ne 0 ]]; then\n  echo \"Error parsing JSON in line $JSON_LINE_ERROR\" 1\u003e\u00262\n  exit 1\nfi\n```\n\nIn case of success, select parsing results. Get value with function `get_json_path_value` call, pointing search path via parameters:\n\n``` bash\nlocal val; get_json_path_value \"val\" \"menu\" \"id\"\necho \"- Select menu/id value = $val\"\nlocal val; get_json_path_value \"val\" \"menu\" \"type\"\necho \"- Select menu/type value = $val\"\n```\n\n, with output:\n\n```\n- Select menu/id value = file\n- Select menu/type value = Word document\n```\n\nPlease note, that with `get_json_path_value` you can also index JSON arrays with integer values:\n\n``` bash\nlocal val; get_json_path_value \"val\" \"menu\" \"popup\" \"menuitem\" 1 \"args\" 2\necho \"- Select menu/popup/menuitem/1/args/2 value = $val\"\nlocal val; get_json_path_value \"val\" \"menu\" \"popup\" \"menuitem\" 0 \"args\" 3\necho \"- Select menu/popup/menuitem/0/args/3 value with unicode = $val\"\n```\n\n, with output:\n\n```\n- Select menu/popup/menuitem/1/args/2 value = 3.1415926\n- Select menu/popup/menuitem/0/args/3 value with unicode = Яndex\n```\n\nYou can find additional usage demo in folder `examples` with BASH scripts: `parse_json_example1.sh`, `parse_json_example2.sh`, `json_parse_file.sh`.\n\nAPI\n---\n\nAPI is limited to following recommended functions:\n\n* `parse_json_from_pipe`: read and parse JSON taken from pipe.\n  Return 0 in case of success, either non zero error code. In case of error `JSON_LINE_ERROR` variable pointing to the line where error found.\n  \u003e *Note*: You don't need to care about, but as a success parse result next internal variables filled with parsed information (tokens):\n  \u003e * `jt_type` - type (object, array, string, primitive)\n  \u003e * `jt_content` - content for strings and primitives\n  \u003e * `jt_parent` - reference to parent token\n  \u003e * `jt_size` - count of direct children subtrees in json structure\n  \u003e * `jt_size_tok` - total number of all child tokens\n\n* `parse_json`: do the same as `parse_json_from_pipe`, but take data from file path passed via parameter.\n* `get_json_path_value`: select JSON value with search path provided via parameters passed to the function from 2nd argument. Function return result to the variable which name specified in 1st argument. Can return JSON array size, if search path point to the array [...] in JSON document. The search path elements are compared with JSON key elements to find matches and it working in case insensitive mode.\n* `print_json_tokens`: for debug purpose. Print the content of variables `jt_type`, `jt_content`, `jt_parent`, `jt_size`, `jt_size_tok` as a result of successful execution of `parse_json` either `parse_json_from_pipe` call.\n\nUnit-tests\n----------\n\nYou can run `json_unit_tests.sh` to verify that library is in working condition in your environment.\nThe output must contain only \"`Test passed`\" results, like this:\n\n```\nTest #20 PASSED. Success status=0. No error parsing JSON/JSONC\nTest #21 PASSED. Success status=0. Result=3.1415926. Expected value for menu/popup/menuitem/0/args/2=3.1415926\n...\nTest #56 PASSED. Success status=2. Error parsing JSON/JSONC in line 9\nTest #57 PASSED. Success status=1. Error parsing JSON/JSONC in line 9\n```\n\nIn case of errors, please, report to [issue tracker](https://github.com/d2r2/jsonc-bash/issues).\n\nCredits\n-------\n\nThis library is inspired by minimalistic JSON parser written by Serge Zaitsev: https://github.com/zserge/jsmn.\n\nLinks\n-----\n\n* Test suite used which cover a lot of parsers, but only one BASH parser found there. Keeps big collection of JSON files to check parser compliance with the standard: https://github.com/nst/JSONTestSuite\n\nLicense\n-------\n\nThis software is distributed under MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd2r2%2Fjsonc-bash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fd2r2%2Fjsonc-bash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd2r2%2Fjsonc-bash/lists"}