ItSolutionStuff.com

Angular Json Pipe Example | Json Pipe in Angular

By Hardik Savani β€’ May 2, 2024
Angular

Hi All,

In this quick example, let's see angular json pipe example. i would like to share with you angular json pipe. you'll learn json pipe angular example. let’s discuss angular json pipe format.

Json pipe help to debug your object or object array because you can not print direct object in view file. so you can display it in json array see. json pipe will use for developing mostly but also widely. here i will show you how to use json pipe in angular 6, angular 7, angular 8, angular 9, angular 10, angular 11, angular 12, angular 13, angular 14, angular 15, angular 16 and angular 17.

I am not going to explain more and more description but i will simply give you syntax and some small examples so you can easily use it in your application.

Syntax:

{{ value_expression | json }}

Json Pipe with Object

import { Component } from '@angular/core';

@Component({

selector: 'my-app',

template: `<div>

<p>{{ myObject }}</p>

<p>{{ myObject | json }}</p>

</div>`,

styleUrls: [ './app.component.css' ]

})

export class AppComponent {

name = 'Angular';

myObject = {

id: 1,

name: "Hardik"

};

}

Output

[object Object]

{ "id": 1, "name": "Hardik" }

Json Pipe with Object Array

import { Component } from '@angular/core';

@Component({

selector: 'my-app',

template: `<div>

<p>{{ myArrayObject }}</p>

<p>{{ myArrayObject | json }}</p>

</div>`,

styleUrls: [ './app.component.css' ]

})

export class AppComponent {

name = 'Angular';

myArrayObject = [

{

id: 1,

name: "Hardik",

roles: [1, 2, 3]

},

{

id: 1,

name: "Harsukh",

roles: [1, 2, 4, 5]

}

];

}

Output

[object Object],[object Object]

[ { "id": 1, "name": "Hardik", "roles": [ 1, 2, 3 ] }, { "id": 1, "name": "Harsukh", "roles": [ 1, 2, 4, 5 ] } ]

I hope it can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

πŸ“Ί Subscribe on YouTube

We Are Recommending You

β˜…

Angular Decimal Pipe Example | Number Pipe in Angular

Read Now β†’
β˜…

Angular Date Pipe Example | Date Pipe in Angular

Read Now β†’
β˜…

Angular Currency Pipe Example | Currency Pipe in Angular

Read Now β†’
β˜…

How to Use Angular Pipe in Component Class?

Read Now β†’
β˜…

How to Pass Multiple Parameters to Pipe in Angular?

Read Now β†’
β˜…

Angular Nl2br Pipe Example

Read Now β†’
β˜…

How to Create Custom Pipe in Angular 9/8?

Read Now β†’