{"id":16538650,"url":"https://github.com/spyoungtech/json-five","last_synced_at":"2025-04-06T22:06:38.375Z","repository":{"id":37936261,"uuid":"264405000","full_name":"spyoungtech/json-five","owner":"spyoungtech","description":"Python JSON5 parser with round-trip preservation of comments","archived":false,"fork":false,"pushed_at":"2025-02-17T20:42:28.000Z","size":227,"stargazers_count":30,"open_issues_count":8,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-30T21:06:13.617Z","etag":null,"topics":["json5"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"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/spyoungtech.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":"2020-05-16T09:43:16.000Z","updated_at":"2025-03-02T13:05:54.000Z","dependencies_parsed_at":"2023-09-26T22:07:56.860Z","dependency_job_id":"d3f53467-a80b-4c78-b0bf-02663ae1b3ff","html_url":"https://github.com/spyoungtech/json-five","commit_stats":{"total_commits":150,"total_committers":5,"mean_commits":30.0,"dds":0.09999999999999998,"last_synced_commit":"da1c38f8a4c37f3555f830dd01f68e6c9c96a152"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spyoungtech%2Fjson-five","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spyoungtech%2Fjson-five/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spyoungtech%2Fjson-five/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spyoungtech%2Fjson-five/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spyoungtech","download_url":"https://codeload.github.com/spyoungtech/json-five/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247557767,"owners_count":20958047,"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":["json5"],"created_at":"2024-10-11T18:46:15.789Z","updated_at":"2025-04-06T22:06:38.355Z","avatar_url":"https://github.com/spyoungtech.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# json-five\n\nJSON5 for Python\n\n[![Documentation Status](https://readthedocs.org/projects/json-five/badge/?version=latest)](https://json-five.readthedocs.io/en/latest/?badge=latest)\n[![Build](https://github.com/spyoungtech/json-five/actions/workflows/unittests.yml/badge.svg)](https://github.com/spyoungtech/json-five/actions/workflows/unittests.yaml)\n[![version](https://img.shields.io/pypi/v/json-five.svg?colorB=blue)](https://pypi.org/project/json-five/)\n[![pyversion](https://img.shields.io/pypi/pyversions/json-five.svg?)](https://pypi.org/project/json-five/)\n[![Coverage](https://coveralls.io/repos/github/spyoungtech/json-five/badge.svg?branch=main)](https://coveralls.io/github/spyoungtech/json-five?branch=main)\n\n## Installation\n\n```\npip install json-five\n```\n\nThis project requires Python 3.8+\n\n\n## Key features\n\n- Supports the JSON5 spec\n- Supports similar interfaces to stdlib `json` module\n- Provides an API for working with abstract model representations of JSON5 documents.\n- Supports round-trip loading, editing, and dumping, preserving non-data elements such as comments (in model-based load/dump)\n\n\n\n# Usage\n\n**NOTE:** the import name is `json5` which differs from the install name.\n\n\nFor basic loading/dumping, the interface is nearly identical to that of the `json` module.\n```python\nimport json5\njson_text = \"\"\"{ // This is a JSON5 comment\n\"foo\": \"bar\", /* this is a JSON5 block\ncomment that can span lines */\nbacon: \"eggs\"  // unquoted Identifiers also work\n}\n\"\"\"\nprint(json5.loads(json_text))\n# {\"foo\": \"bar\", \"bacon\": \"eggs\"}\n\nwith open('myfile.json5') as f:\n    data = json5.load(f)\n```\n\nFor loading JSON5, the same parameters `object_hook`, `object_pairs_hook` and `parse_*` keyword arguments are available\nhere for `load`/`loads`.\n\nAdditionally, a new hook, `parse_json5_identifiers`, is available to help users control the\noutput of parsing identifiers. By default, JSON5 Identifiers in object keys are returned as a `JsonIdentifier` object,\nwhich is a subclass of `str` (meaning it's compatible anywhere `str` is accepted).\nThis helps keep keys the same round-trip, rather than converting unquoted identifiers into\n strings:\n\n```python\n\u003e\u003e\u003e text = '{bacon: \"eggs\"}'\n\u003e\u003e\u003e json5.dumps(json5.loads(text)) == text\nTrue\n```\n\nYou can change this behavior with the `parse_json5_identifiers` argument with a callable that receives the `JsonIdentifier` object\nand its return value is used instead. For example, you can specify `parse_json5_identifiers=str` to convert identifiers\nto strings.\n\n```python\n\u003e\u003e\u003e json5.dumps(json5.loads(text, parse_json5_identifiers=str))\n'{\"bacon\": \"eggs\"}'\n```\n\n\n## Custom loaders; Abstract JSON5 Models\n\n**Note:** the underlying model API and tokens are not stable and are subject to breaking changes, even in minor releases.\n\njson-five also features an API for representing JSON5 as an abstract model. This enables a wide degree of capabilities for\nvarious use-cases, such as linters, formatters, custom serialization/deserialization, and more.\n\n\nExample: a simple model\n\n```python\nfrom json5.loader import loads, ModelLoader\njson_string = \"\"\"{foo: \"bar\"}\"\"\"\nmodel = loads(json_string, loader=ModelLoader())\n```\nThe resulting model object looks something like this:\n```python\nJSONText(\n    value=JSONObject(\n        keys=[Identifier(name=\"foo\", raw_value=\"foo\")],\n        values=[DoubleQuotedString(characters=\"bar\", raw_value='\"bar\"')],\n        trailing_comma=None,\n    )\n)\n```\n\n\nIt is possible to make edits to the model, which will affect the output when dumped using the model dumper. However,\nthere is (currently) no validation to ensure your model edits won't result in invalid JSON5 when dumped.\n\nYou may also implement custom loaders and dumpers to control serialization and deserialization. See the [full documentation](https://json-five.readthedocs.io/en/latest/extending.html#custom-loaders-and-dumpers)\nfor more information.\n\n## Tokenization\n\nYou can also leverage tokenization of JSON5:\n\n```python\nfrom json5.tokenizer import tokenize\n\njson_string = \"\"\"{foo: \"bar\"}\"\"\"\nfor tok in tokenize(json_string):\n    print(tok.type)\n```\nOutput would be:\n```text\nLBRACE\nNAME\nCOLON\nWHITESPACE\nDOUBLE_QUOTE_STRING\nRBRACE\n```\n\n# Status\n\nThis project currently fully supports the JSON5 spec and its interfaces for loading and dumping JSON5 is stable as of v1.0.0.\nThere is still active development underway, particularly for the underlying abstract JSON5 model representations and\nability to perform edits using the abstract model.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspyoungtech%2Fjson-five","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspyoungtech%2Fjson-five","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspyoungtech%2Fjson-five/lists"}