0%

angular-pipe-json

The built-in pipe json is used to convert a JavaScript object into a JSON string. It is useful for debugging purposes or when you need to display the raw JSON data in your Angular application.

Usage

Assume you have a data object in your components which is an javascript object:

1
2
3
4
5
6
{
"userId": 1,
"id": 20,
"title": "ullam nobis libero sapiente ad optio sint",
"completed": true
}

In your template file, you can use the json pipe to convert the object into a JSON string:

1
<pre>{{ data | json }}</pre>

You will get the following output on the rendered page:

1
{ "userId": 1, "id": 20, "title": "ullam nobis libero sapiente ad optio sint", "completed": true }

Without the json pipe, you will get [object Object] in the output.