angular.filter.json
Description
Allows you to convert a JavaScript object into JSON string.
This filter is mostly useful for debugging. When using the double curly {{value}} notation
the binding is automatically converted to JSON.
Usage
In HTML Template Binding
{{
object_expression
| json }}
In JavaScript
angular.filter.json(object);
Parameters
- object –
{*}
– Any JavaScript object (including arrays and primitive types) to filter.
Returns
{string} JSON string.
CSS
ng-monospace Always applied to the encapsulating element.
Example
<input type="text" name="objTxt" value="{a:1, b:[]}"
ng:eval="obj = $eval(objTxt)"/>
<pre>{{ obj | json }}</pre>
it('should jsonify filtered objects', function() {
expect(binding('obj | json')).toBe('{\n "a":1,\n "b":[]}');
});
it('should update', function() {
input('objTxt').enter('[1, 2, 3]');
expect(binding('obj | json')).toBe('[1,2,3]');
});