Skip to content

API Reference


API Reference / @dasch-ng/json-viewer

@dasch-ng/json-viewer

JSON formatter and viewer for Angular

Note: This library is a maintained fork of hivivo/ngx-json-viewer, updated for modern Angular versions with standalone components and signal-based inputs.

Features

  • 🌲 Interactive tree view for JSON data
  • 🎨 Type-specific syntax highlighting
  • 🔄 Circular reference detection
  • 📦 Standalone component (no module required)
  • 🎯 Fully typed with TypeScript
  • 🎨 Customizable theming with CSS variables
  • 🚀 Modern Angular (v21+) with signals

Installation

bash
npm install @dasch-ng/json-viewer

or

bash
bun add @dasch-ng/json-viewer

Usage

Basic Usage

Since this is a standalone component, you can import it directly in your component:

typescript
import { Component } from '@angular/core';
import { JsonViewerComponent } from '@dasch-ng/json-viewer';

@Component({
  selector: 'app-root',
  imports: [JsonViewerComponent],
  template: ` <json-viewer [json]="data" /> `,
})
export class AppComponent {
  data = {
    name: 'John Doe',
    age: 30,
    hobbies: ['reading', 'coding'],
  };
}

Configuration Options

Collapse all nodes initially

html
<json-viewer [json]="data" [expanded]="false" />

Limit expansion depth

html
<json-viewer [json]="data" [depth]="3" />

API

InputTypeDefaultDescription
jsonunknownrequiredThe JSON data to display
expandedbooleantrueWhether to expand all nodes by default
depthnumber-1Maximum depth to expand (-1 for unlimited)

Theming

Customize the appearance using CSS variables. You can override these in your global styles or component styles:

css
json-viewer {
  --ngx-json-font-family: 'Monaco', 'Courier New', monospace;
  --ngx-json-font-size: 14px;

  /* Value colors */
  --ngx-json-string: #22863a;
  --ngx-json-number: #005cc5;
  --ngx-json-boolean: #d73a49;
  --ngx-json-date: #6f42c1;
  --ngx-json-null: #6a737d;
  --ngx-json-null-bg: #ffeef0;
  --ngx-json-undefined: #6a737d;

  /* Structure colors */
  --ngx-json-array: #24292e;
  --ngx-json-object: #24292e;
  --ngx-json-function: #6f42c1;

  /* UI colors */
  --ngx-json-key: #005cc5;
  --ngx-json-separator: #24292e;
  --ngx-json-value: #24292e;
  --ngx-json-toggler: #586069;
  --ngx-json-undefined-key: #959da5;
}

Available CSS Variables

VariableDescriptionDefault
--ngx-json-font-familyFont familymonospace
--ngx-json-font-sizeFont size1em
--ngx-json-stringString value color#FF6B6B
--ngx-json-numberNumber value color#009688
--ngx-json-booleanBoolean value color#B938A4
--ngx-json-dateDate value color#05668D
--ngx-json-nullNull value color#fff
--ngx-json-null-bgNull background colorred
--ngx-json-undefinedUndefined value color#fff
--ngx-json-arrayArray label color#999
--ngx-json-objectObject label color#999
--ngx-json-functionFunction value color#999
--ngx-json-keyKey color#4E187C
--ngx-json-separatorSeparator color#999
--ngx-json-valueDefault value color#000
--ngx-json-togglerExpand/collapse icon color#787878
--ngx-json-undefined-keyUndefined key color#999

Credits

This library is based on ngx-json-viewer by hivivo, modernized for Angular 21+ with:

  • Standalone components
  • Signal-based inputs
  • Modern TypeScript patterns
  • Updated dependencies

License

MIT

@dasch-ng/json-viewer - JSON formatter and viewer for Angular

Remarks

This library provides a modern Angular component for displaying JSON data in an interactive tree view with syntax highlighting and circular reference detection.

Classes

Interfaces

Type Aliases

Released under the MIT License.