{"id":14990106,"url":"https://github.com/mohsen1/pretty-json","last_synced_at":"2025-04-12T02:05:24.460Z","repository":{"id":233319916,"uuid":"784861490","full_name":"mohsen1/pretty-json","owner":"mohsen1","description":"Pretty JSON HTML Custom Element","archived":false,"fork":false,"pushed_at":"2025-04-10T07:27:24.000Z","size":19280,"stargazers_count":31,"open_issues_count":8,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-12T02:05:17.877Z","etag":null,"topics":["custom-elements","html","json","web-components"],"latest_commit_sha":null,"homepage":"https://azimi.me/pretty-json","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mohsen1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-04-10T17:49:27.000Z","updated_at":"2025-04-10T07:26:45.000Z","dependencies_parsed_at":"2024-04-15T19:25:07.668Z","dependency_job_id":"be32a4b2-b081-4e98-8760-29151f10fc46","html_url":"https://github.com/mohsen1/pretty-json","commit_stats":null,"previous_names":["mohsen1/pretty-json"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohsen1%2Fpretty-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohsen1%2Fpretty-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohsen1%2Fpretty-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohsen1%2Fpretty-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mohsen1","download_url":"https://codeload.github.com/mohsen1/pretty-json/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248505863,"owners_count":21115354,"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":["custom-elements","html","json","web-components"],"created_at":"2024-09-24T14:19:27.887Z","updated_at":"2025-04-12T02:05:24.436Z","avatar_url":"https://github.com/mohsen1.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `\u003cpretty-json\u003e` HTML Custom Element\n\n[**See the live demo**](https://azimi.me/pretty-json/)\n\n`\u003cpretty-json\u003e` is an HTML custom element that allows you to render JSON objects in HTML documents with human-readable formatting and expandable interaction for browsing deep JSON structures.\n\n## Usage\n\nInclude [`pretty-json-custom-element/index.js`](https://github.com/mohsen1/pretty-json/blob/main/index.js) in your HTML page and use the HTML custom element as follows:\n\n\u003c!-- prettier-ignore-start --\u003e\n```html\n\u003cscript defer src=\"https://unpkg.com/pretty-json-custom-element/index.js\"\u003e\u003c/script\u003e\n\u003cpretty-json\u003e\n{\n  \"hello\": \"world\",\n  \"value\": 42,\n  \"enabled\": true,\n  \"extra\": null,\n  \"nested\": { \"key\": \"value\" }\n}\n\u003c/pretty-json\u003e\n````\n\u003c!-- prettier-ignore-end --\u003e\n\nYour JSON will be rendered as a human-readable format:\n\n\u003cpicture\u003e\n  \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://github.com/mohsen1/pretty-json/raw/main/screenshot-dark.png\" /\u003e\n  \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://github.com/mohsen1/pretty-json/raw/main/screenshot.png\" /\u003e\n  \u003cimg src=\"https://github.com/mohsen1/pretty-json/raw/main/screenshot.png\" alt=\"Screenshot\" width=\"200px\" /\u003e\n\u003c/picture\u003e\n\n## Features\n\n- Outputs a valid JSON string that can be copied and pasted into a JSON file\n- HTML Custom Element without any dependencies, works in any modern browser\n- No need to install any dependencies or build tools, just drop the script in your HTML and start using it\n- Allows a high level of customization using CSS variables\n- Display large JSON objects with expandable and collapsible sections\n- Supports truncating very large strings and arrays with an ellipsis\n\n## To-do List\n\n- [ ] Support grouping very large arrays\n\n## Attributes\n\nYou can customize the rendering of the JSON object by setting the following attributes on the `\u003cpretty-json\u003e` element:\n\n### `expand`\n\nBy default, the JSON object is rendered expanded up to 1 level deep. You can set the `expand` attribute to a number to expand the JSON object up to that level deep:\n\n```html\n\u003cpretty-json expand=\"2\"\u003e{\"hello\": {\"world\": \"!\"}}\u003c/pretty-json\u003e\n```\n\n#### Collapsed by default\n\nYou can set the `expand` attribute to `0` to render the JSON object collapsed by default:\n\n```html\n\u003cpretty-json expand=\"0\"\u003e{\"hello\": {\"world\": \"!\"}}\u003c/pretty-json\u003e\n```\n\n### `truncate-string`\n\nBy default, strings longer than 500 characters are truncated with an ellipsis. You can set the `truncate-string` attribute to a number to truncate strings longer than that number of characters:\n\n```html\n\u003cpretty-json truncate-string=\"10\"\u003e\n  {\"hello\": \"long string that will be truncated\"}\n\u003c/pretty-json\u003e\n```\n\n## Customization\n\nYou can customize the appearance of the rendered JSON using CSS variables:\n\n```css\npretty-json {\n  --key-color: #cc0000;\n  --arrow-color: #737373;\n  --brace-color: #0030f0;\n  --bracket-color: #0030f0;\n  --string-color: #009900;\n  --number-color: #0000ff;\n  --null-color: #666666;\n  --boolean-color: #d23c91;\n  --comma-color: #666666;\n  --ellipsis-color: #666666;\n  --indent: 2rem;\n  --font-family: monospace;  \n  --font-size: 1rem;  \n}\n\n/* Also handle the dark mode */\n@media (prefers-color-scheme: dark) {\n  pretty-json {\n    --key-color: #f73d3d;\n    --arrow-color: #6c6c6c;\n    --brace-color: #0690bc;\n    --bracket-color: #0690bc;\n    --string-color: #21c521;\n    --number-color: #0078b3;\n    --null-color: #8c8888;\n    --boolean-color: #c737b3;\n    --comma-color: #848181;\n    --ellipsis-color: #c2c2c2;\n    --indent: 2rem;\n    --font-family: monospace;\n    --font-size: 1rem;\n  }\n}\n```\n\n## Development\n\nTo run the development server:\n\n```bash\nyarn install\nyarn start\n```\n\n### Running tests\n\nThis repository uses Playwright for testing.\n\nTo run the tests:\n\n```bash\nyarn test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohsen1%2Fpretty-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmohsen1%2Fpretty-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohsen1%2Fpretty-json/lists"}