There's probably a nicer Angular or JS JSON Tree viewer, but this can get you started. You need to recursively iterate through your objects.

I'm using recursive template outlets here, you may be able to do components (and if you need to add other functionality its probably worth looking into that).

Here's a demo on stack blitz: https://stackblitz.com/edit/angular-ivy-qadvlr?file=src%2Fapp%2Fapp.component.ts

Example component, it just has your data as an array, and a helper method to try and determine the type of value we got passed in, since its type will determine how we need to display it.

export class AppComponent  {
  data1 = [
    {
      "name": "d1",
      "days": [
        "monday",
        "wednesday",
      ],
      "options": {
        "name": "o1",
        "extras": [],
        "temp": [
          "12",
          "25",
          "12"
        ]
      }
    },
    {
      "name": "d2",
      "days": [
        "tuesday",
        "wednesday",
      ],
      "options": {
        "name": "o2a",
        "extras": [
          {
            name: 'extra 1'
          }
        ],
        "temp": [
          "22",
          "25",
          "12"
        ]
      }
    }
  ]

  getType(val: any) {
    if (Array.isArray(val)) {// aray's will be type of "object" so need specail cases, and possibly others but this is a good start
      return 'array';
    } else if (typeof val === 'string' || val instanceof String) {
      return 'string';
    } else if (typeof val === 'boolean') {
      return 'boolean';
    } else if (typeof val === "object") {
      return 'object'
    }
  }

}

Kinda messy, recursive templates that don't care about property names. Instead we use Angular's keyvalue pipe to get the keys/values of an object.

<ul *ngFor="let someObj of data1;">
  <ng-container *ngTemplateOutlet="objectTemplate; context: {obj: someObj}"></ng-container>
</ul>


<ng-template #recursiveTemplate let-key="key" let-valueType="valueType" let-value="value">
  {{key}}

  <ng-container [ngSwitch]="valueType">

      <ng-container *ngSwitchCase="'array'">
        <ng-container *ngTemplateOutlet="arrayTemplate; context: { value: value}"></ng-container>
      </ng-container>

      <ng-container *ngSwitchCase="'object'">
        <ul>
        <ng-container *ngTemplateOutlet="objectTemplate; context: {obj: value}"></ng-container>
        </ul>
      </ng-container>

      <!-- anything we might have missed or don't needs anything special for, just show it as JSON -->
      <ng-container *ngSwitchDefault>
         {{key ? "- " : ""}}{{value | json}}
      </ng-container>

  </ng-container>
</ng-template>

<ng-template #arrayTemplate let-value="value">
  <ul>
    <li *ngFor="let child of value;">
        <ng-container *ngTemplateOutlet="recursiveTemplate; context:{ key:null, valueType: getType(child), value: child }"></ng-container>
    </li>
  </ul>
</ng-template>

<ng-template #objectTemplate let-obj="obj">
  <li *ngFor="let item of obj | keyvalue;">
  <ng-container *ngTemplateOutlet="recursiveTemplate; context:{ key:item.key, valueType: getType(item.value), value: item.value }"></ng-container>
  </li>
</ng-template>
Answer from cjd82187 on Stack Overflow
🌐
npm
npmjs.com › package › ngx-json-viewer
ngx-json-viewer - npm
JSON formatter / viewer for Angular. Latest version: 3.2.1, last published: 3 years ago. Start using ngx-json-viewer in your project by running `npm i ngx-json-viewer`. There are 44 other projects in the npm registry using ngx-json-viewer.
      » npm install ngx-json-viewer
    
Published   Nov 21, 2022
Version   3.2.1
Author   Vivo Xu
🌐
GitHub
github.com › gofynd › angular-json-viewer
GitHub - gofynd/angular-json-viewer: Angular2+ JSON Viewer component. JSON in HTML with syntax highlight like Chrome DevTools. · GitHub
Angular2+ JSON Viewer component. JSON in HTML with syntax highlight like Chrome DevTools. - gofynd/angular-json-viewer
Author   gofynd
🌐
StackBlitz
stackblitz.com › edit › angular-txwrtv
JSON Viewer and Editor - StackBlitz
A angular-cli project based on rxjs, tslib, core-js, zone.js, @angular/core, @angular/forms, @angular/common, @angular/router, @angular/compiler, @angular/animations, @angular/platform-browser and @angular/platform-browser-dynamic.
🌐
GitHub
github.com › hivivo › ngx-json-viewer
GitHub - hivivo/ngx-json-viewer: JSON formatter and viewer in HTML for Angular · GitHub
JSON formatter and viewer in HTML for Angular. Contribute to hivivo/ngx-json-viewer development by creating an account on GitHub.
Starred by 182 users
Forked by 72 users
Languages   TypeScript 68.2% | SCSS 13.3% | HTML 9.0% | JavaScript 9.0% | CSS 0.5%
Top answer
1 of 3
2

There's probably a nicer Angular or JS JSON Tree viewer, but this can get you started. You need to recursively iterate through your objects.

I'm using recursive template outlets here, you may be able to do components (and if you need to add other functionality its probably worth looking into that).

Here's a demo on stack blitz: https://stackblitz.com/edit/angular-ivy-qadvlr?file=src%2Fapp%2Fapp.component.ts

Example component, it just has your data as an array, and a helper method to try and determine the type of value we got passed in, since its type will determine how we need to display it.

export class AppComponent  {
  data1 = [
    {
      "name": "d1",
      "days": [
        "monday",
        "wednesday",
      ],
      "options": {
        "name": "o1",
        "extras": [],
        "temp": [
          "12",
          "25",
          "12"
        ]
      }
    },
    {
      "name": "d2",
      "days": [
        "tuesday",
        "wednesday",
      ],
      "options": {
        "name": "o2a",
        "extras": [
          {
            name: 'extra 1'
          }
        ],
        "temp": [
          "22",
          "25",
          "12"
        ]
      }
    }
  ]

  getType(val: any) {
    if (Array.isArray(val)) {// aray's will be type of "object" so need specail cases, and possibly others but this is a good start
      return 'array';
    } else if (typeof val === 'string' || val instanceof String) {
      return 'string';
    } else if (typeof val === 'boolean') {
      return 'boolean';
    } else if (typeof val === "object") {
      return 'object'
    }
  }

}

Kinda messy, recursive templates that don't care about property names. Instead we use Angular's keyvalue pipe to get the keys/values of an object.

<ul *ngFor="let someObj of data1;">
  <ng-container *ngTemplateOutlet="objectTemplate; context: {obj: someObj}"></ng-container>
</ul>


<ng-template #recursiveTemplate let-key="key" let-valueType="valueType" let-value="value">
  {{key}}

  <ng-container [ngSwitch]="valueType">

      <ng-container *ngSwitchCase="'array'">
        <ng-container *ngTemplateOutlet="arrayTemplate; context: { value: value}"></ng-container>
      </ng-container>

      <ng-container *ngSwitchCase="'object'">
        <ul>
        <ng-container *ngTemplateOutlet="objectTemplate; context: {obj: value}"></ng-container>
        </ul>
      </ng-container>

      <!-- anything we might have missed or don't needs anything special for, just show it as JSON -->
      <ng-container *ngSwitchDefault>
         {{key ? "- " : ""}}{{value | json}}
      </ng-container>

  </ng-container>
</ng-template>

<ng-template #arrayTemplate let-value="value">
  <ul>
    <li *ngFor="let child of value;">
        <ng-container *ngTemplateOutlet="recursiveTemplate; context:{ key:null, valueType: getType(child), value: child }"></ng-container>
    </li>
  </ul>
</ng-template>

<ng-template #objectTemplate let-obj="obj">
  <li *ngFor="let item of obj | keyvalue;">
  <ng-container *ngTemplateOutlet="recursiveTemplate; context:{ key:item.key, valueType: getType(item.value), value: item.value }"></ng-container>
  </li>
</ng-template>
2 of 3
2

You are writing <li>{{dat.name}}</li> and expecting everything to work if the key name gets changed, then its not possible.

However, If you just want to display the whole JSON in your UI, you can use json pipe like ::

<li>{{dat | json}}</li>

If you want the JSON gets displayed in pretty printed format, please change to ::

<div *ngFor="let dat of data">
    <pre>{{dat | json}}</pre>
</div>
🌐
GitHub
github.com › gofynd › angular-json-viewer › blob › master › README.md
angular-json-viewer/README.md at master · gofynd/angular-json-viewer
Angular2+ JSON Viewer component. JSON in HTML with syntax highlight like Chrome DevTools. - angular-json-viewer/README.md at master · gofynd/angular-json-viewer
Author   gofynd
Find elsewhere
🌐
GitHub
github.com › killzoner › ng-json-view
GitHub - killzoner/ng-json-view: A JSON View component for Angular 10+
A JSON View component for Angular 10+ (an angular based JSON display component)
Starred by 13 users
Forked by 8 users
Languages   TypeScript 74.0% | HTML 15.5% | CSS 10.5% | TypeScript 74.0% | HTML 15.5% | CSS 10.5%
🌐
npm
npmjs.com › package › ang-jsoneditor
ang-jsoneditor - npm
View/Edit Json file with formatting. ... Working with latest Angular 18/19.
      » npm install ang-jsoneditor
    
Published   Apr 09, 2025
Version   4.0.2
Author   Mario Mol
🌐
Bennadel
bennadel.com › blog › 3710-creating-an-interactive-json-explorer-using-css-grid-in-angular-9-0-0-next-14.htm
Creating An Interactive JSON Explorer Using CSS Grid In Angular 9.0.0-next.14
October 28, 2019 - Ben Nadel created a JSON Explorer app using CSS Grid and Angular 9.0.0-next.14. This app takes a JSON payload and parses into an interactive user experience that makes it easier to investigate and review large JSON values (such as those coming out of Loggly).
🌐
GitHub
github.com › augmity › agm-json-viewer
GitHub - augmity/agm-json-viewer: Angular JSON Viewer component
Angular JSON Viewer component. Collapsible JSON in HTML with syntax highlight like in ie.
Forked by 2 users
Languages   TypeScript 63.3% | CSS 23.6% | HTML 13.1% | TypeScript 63.3% | CSS 23.6% | HTML 13.1%
🌐
GitHub
github.com › n3wtron › ngx-json-viewer2
GitHub - n3wtron/ngx-json-viewer2: JSON formatter and viewer in HTML for Angular 2/4/5/6/7+
JSON formatter and viewer in HTML for Angular 2/4/5/6/7+ - n3wtron/ngx-json-viewer2
Author   n3wtron
🌐
CodeSandbox
codesandbox.io › examples › package › @gofynd › angular-json-viewer
@gofynd/angular-json-viewer examples - CodeSandbox
Use this online @gofynd/angular-json-viewer playground to view and fork @gofynd/angular-json-viewer example apps and templates on CodeSandbox.
🌐
CodeSandbox
codesandbox.io › examples › package › ngx-json-viewer
ngx-json-viewer examples - CodeSandbox
Use this online ngx-json-viewer playground to view and fork ngx-json-viewer example apps and templates on CodeSandbox.