AngularJS: API: ng/filter/json


json

  1. - filter in module ng

Allows you to convert a JavaScript object into JSON string.

This filter is mostly useful for debugging. When using the double curly notation the binding is automatically converted to JSON.

Usage

In HTML Template Binding

{{ json_expression | json}}

In JavaScript

$filter('json')(object)

Arguments

ParamTypeDetails
object*

Any JavaScript object (including arrays and primitive types) to filter.

Returns

string

JSON string.

Example

index.html
<pre>{{ {'name':'value'} | json }}</pre>
protractor.js
it('should jsonify filtered objects', function() {
  expect(element(by.binding("{'name':'value'}")).getText()).toMatch(/\{\n  "name": ?"value"\n}/);});