This is the archived documentation for Angular v5. Please visit angular.io to see documentation for the current version of Angular.

JsonPipe

npm Package @angular/common
Module import { JsonPipe } from '@angular/common';
Source common/src/pipes/json_pipe.ts
NgModule CommonModule

Converts value into JSON string.

How To Use

expression | json

Description

Converts value into string using JSON.stringify. Useful for debugging.

Example

      
      @Component({
  selector: 'json-pipe',
  template: `<div>
    <p>Without JSON pipe:</p>
    <pre>{{object}}</pre>
    <p>With JSON pipe:</p>
    <pre>{{object | json}}</pre>
  </div>`
})
export class JsonPipeComponent {
  object: Object = {foo: 'bar', baz: 'qux', nested: {xyz: 3, numbers: [1, 2, 3, 4, 5]}};
}