Gathering detailed insights and metrics for @alenaksu/json-viewer
Gathering detailed insights and metrics for @alenaksu/json-viewer
Gathering detailed insights and metrics for @alenaksu/json-viewer
Gathering detailed insights and metrics for @alenaksu/json-viewer
@darekodz/json-viewer
[](https://github.com/alenaksu/json-viewer/releases) [](https://www.npmjs.com/package/@alenaksu/json-viewer) [](https://github.com/alenaksu/json-viewer/releases) [](https://www.npmjs.com/package/@alenaksu/json-viewer) [](https://github.com/alenaksu/json-viewer/releases) [](https://www.npmjs.com/package/@alenaksu/json-viewer) [![down
Web Component to visualize JSON data in a tree view
npm install @alenaksu/json-viewer
Typescript
Module System
Node Version
NPM Version
TypeScript (53.19%)
JavaScript (19.64%)
CSS (18.7%)
HTML (8.47%)
Total Downloads
797,080
Last Day
202
Last Week
10,999
Last Month
59,638
Last Year
488,720
MIT License
210 Stars
154 Commits
34 Forks
4 Watchers
12 Branches
7 Contributors
Updated on Jun 13, 2025
Latest Version
2.1.2
Package Id
@alenaksu/json-viewer@2.1.2
Unpacked Size
379.03 kB
Size
97.23 kB
File Count
18
NPM Version
10.8.2
Node Version
20.18.0
Published on
Oct 29, 2024
Cumulative downloads
Total Downloads
Last Day
-35.5%
202
Compared to previous day
Last Week
-4.2%
10,999
Compared to previous week
Last Month
-26.8%
59,638
Compared to previous month
Last Year
142.5%
488,720
Compared to previous year
1
A Web Component to visualize JSON data in a tree view
The package contains a bundled version of the component which includes also the Lit library. It can be useful in case you want to import the package using a CDN.
1<script src="https://unpkg.com/@alenaksu/json-viewer@2.1.0/dist/json-viewer.bundle.js"></script>
Install the component through NPM:
1npm i @alenaksu/json-viewer
Import the package to your project, this way the component will be automatically defined in the custom elements registry with its default tag name json-viewer
.
1import '@alenaksu/json-viewer';
If you want to extend the component or if you just need to use it in scoped registries with a different tag name, then you can import the component class from the package:
1import { JsonViewer } '@alenaksu/json-viewer/JsonViewer.js'; 2 3class MyJsonViewer extends JsonViewer { 4 ... 5} 6 7customElements.define('my-json-viewer', MyJsonViewer);
1<json-viewer></json-viewer>
data
- the string representation of JSON object to loaddata
- get/set the JSON objectfilter (regexOrPath: RegExp|string) => void
| Maintains only the nodes that match the given criteriaresetFilter () => void
| Clear the filterexpand (regexOrPath: RegExp|string) => void
| Expand all the nodes that match the given criteriaexpandAll () => void
| Alias for expand('**')
collapse (regexOrPath: RegExp|string) => void
| Collapse all the nodes that match the given criteriacollapseAll () => void
| Alias for collapse('**')
search (regexOrPath: RegExp|string) => Iterator
| Return and iterator with which is possible to go through all the matched nodes. It scrolls the page to the node and highlights it.object
- The object wrapper element.property
- The wrapper element of a property.key
- The key element of a property.primitive
- The primitive value.primitive--string
- Applied when the primitive is a string.primitive--number
- Applied when the primitive is a number.primitive--boolean
- Applied when the primitive is a boolean.primitive--null
- Applied when the primitive is a null.preview
- The value preview of a property.highlight
- The highlighted value.The appearance of the component can be modified by changing the CSS custom properties
1json-viewer { 2 /* Background, font and indentation */ 3 --background-color: #2a2f3a; 4 --color: #f8f8f2; 5 --font-family: Nimbus Mono PS, Courier New, monospace; 6 --font-size: 1rem; 7 --line-height: 1.2rem; 8 --indent-size: 0.5em; 9 --indentguide-size: 1px; 10 --indentguide-style: solid; 11 --indentguide-color: #333; 12 --indentguide-color-active: #666; 13 --indentguide: var(--indentguide-size) var(--indentguide-style) var(--indentguide-color); 14 --indentguide-active: var(--indentguide-size) var(--indentguide-style) var(--indentguide-color-active); 15 --outline-color: #e0e4e5; 16 --outline-width: 1px; 17 --outline-style: dotted; 18 19 /* Types colors */ 20 --string-color: #a3eea0; 21 --number-color: #d19a66; 22 --boolean-color: #4ba7ef; 23 --null-color: #df9cf3; 24 --property-color: #6fb3d2; 25 26 /* Collapsed node preview */ 27 --preview-color: #deae8f; 28 29 /* Search highlight color */ 30 --highlight-color: #c92a2a; 31}
Put the JSON inside the element
1<json-viewer> 2 { "quiz": { "sport": { "q1": { "question": "Which one is correct team name in NBA?", "options": [ "New York Bulls", 3 "Los Angeles Kings", "Golden State Warriros", "Huston Rocket" ], "answer": "Huston Rocket" } }, "maths": { "q1": { 4 "question": "5 + 7 = ?", "options": [ "10", "11", "12", "13" ], "answer": "12" }, "q2": { "question": "12 - 8 = ?", 5 "options": [ "1", "2", "3", "4" ], "answer": "4" } } } } 6</json-viewer>
1<json-viewer id="json"></json-viewer> 2 3<script> 4 document.querySelector('#json').data = { prop1: true, prop2: 'test' }; 5</script>
1const viewer = document.querySelector('#json'); 2 3// Expand/collapse/filter 4viewer.expand('**.name'); 5viewer.collapse(/name/); 6viewer.filter('test.*.name'); 7 8// Search 9const searchIterator = viewer.search('value'); 10// Scrolls to the node and highlight the value 11searchIterator.next();
This is an experimental feature and it may change in the future
The rendering of the values can be customized by defining a static method customRenderer
in the custom element class.
The function receives the value and the path of the node and it should return a HTML node or a Lit's TemplateResult
object.
1import { JsonViewer } from '@alenaksu/json-viewer/JsonViewer.js'; 2 3customElements.define( 4 'json-viewer', 5 class extends JsonViewer { 6 static styles = [ 7 JsonViewer.styles, 8 css` 9 a { 10 color: white; 11 text-decoration: underline; 12 } 13 ` 14 ]; 15 16 static customRenderer(value, path) { 17 if (typeof value === 'string') { 18 if (URL.canParse(value)) { 19 return html`<a href="${value}" target="_blank">${value}</a>`; 20 } else if (Date.parse(value)) { 21 return new Date(value).toLocaleString(); 22 } 23 } else if (typeof value === 'number') { 24 return value.toFixed(2); 25 } 26 27 return super.customRenderer(value); 28 } 29 } 30); 31
The demo can also be run locally with
1npm run start
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
1 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
Found 1/14 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
11 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More